Do you ever have a need to print the contents of a folder or entire directory tree in Windows XP or Vista?
If you do, Microsoft has a knowledge base article that will add "Print Directory" to Windows Explorer right click menu which will print the folder contents (or directory tree) that you are currently viewing.
But the problem with Microsoft's solution in Step 2 is that File Types \ Advanced option in Folder Options does not exist in Vista, and for XP you need to hack the registry to prevent the Search Companion window from opening when you try to open the folder using Windows Explorer.
FORGET THAT CRAP!
Fortunantly there's an easier way to use this feature without messing around in the registry or searching all day for the Advanced button that doesn't exist.
To do this, we'll use Step 1 as described in the knowledge base article, and create the batch file which will include the commands needed for printing.
Creating The Printdir Batch File
- Open Notepad by clicking on Start \ Run and enter notepad in the Run dialog box and click OK.
- Copy and paste the following text into Notepad:
dir %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit
- Close Notepad and click Yes to save the changes.
- In the Save As dialog box, copy and paste the following text in the File name: field (shown in below screen shot):
%windir%\Printdir.bat
- Select All Files (*.*) in the Save as type: drop down field. Then Click Save.
The Printdir.bat file has now been saved in the \Windows folder.
Next, we'll need create a shortcut to the Printdir.bat file in the Send To folder.
Create Printdir Shortcut
- In Vista, click on Start \ Run and enter the following in the Run dialog box and click OK
%APPDATA%\Microsoft\Windows\SendTo
(NOTE: %APPDATA% is an environment variable that points to your user name AppData\Roaming folder).
- In XP, click on Start \ Run and enter the following in the Run dialog box and click OK (%USERPROFILE% is an environment variable that points to your use name Documents and Settings folder).
%USERPROFILE%\SendTo
- In the SendTo folder, right click and select New \ Shortcut.
- Type %windir%\Printdir.bat in the "Type the location of the item:" field and click Next.
- Type Print Directory Listing in the "Type a name for this shortcut" and click Finish.
Now when you have the need to print a directory tree of folder contents from Windows Explorer, just right click and select Send To \ Print Directory Listing.
Much better than mucking around in the registry!
Hey What About Printing From The Command Prompt?
Yea, if you like to work at the command prompt, you can just type printdir.bat (if you created the batch file) at the prompt or enter the following command:
dir /-p /o:gn > %temp%\Listing | start /w notepad /p %temp%\Listing
The command is similar to what we used in the Printdir.bat file, except were "piping" the command together with the "|" character (found above the Enter key and holding Shift down).
By using "|" (SHIFT+\ above Enter key), it allows you to execute two commands at once. Every time you execute, it will over write the file "Listing" so you don't need to worry about deleting it.
Cool!
Comments on How To Print A Directory Tree From Windows Explorer
I can't get to save the batch file to the windows location as I need administrator prevlidges. I thought that once I own the PC I would have all the permissions I need!
Just one other thing,
This does not print sub folders. is there a way of doing this without expanding?
@Gerard
Sounds like you are using an account that does not have admin privileges and you will need to authenticate as the admin account or just logon as the administrator to set this up on your computer.
To print the contents of sub-folders use dir /s
How does one combine the Print Directory Script and Print Subdirectories scripts into one command? I'd like to be able to save these lists as well. Any help is appreciated.
@Charles
Not sure what two scripts you are referring to. The article only mentions one script.
If you want to print sub-directories, change the command as mentioned in the comment above. That command will print the directory itself and sub directories.
Watching The Net,
Thank you, You are awesome. How could I script a "Save Directory Tree" script so as to save a softcopy directory listing?
Respectfully,
Charles
@Charles
To do that, just remove the following line from the batch file.
del "%temp%\Listing"
The batch file will now save to a file (with out deleting it) and also print.
Got the batch file set up and it works great. Where in the Windows\folder do I change the batch file to remove the line mentioned about so that the file will now save in addition to print?
Also, can the batch file be modified to time and file size information for a cleaner printout? Thanks!!
@Barry
The batch file is saved off the root of the Windows folder. Look for the file: Printdir.bat.
If you are looking for more options to use with the dir command, just open up a command prompt and type the following:
dir /?
This will display help info for the dir command and list all options that can be used.
This works great printing the directory…. but does anyone know how to print mutiple open subflodes…. you can do them individually, but not many at the same time?
Using your suggestion listed above, I have been able to print directories. Thank you for your assistance in this modification. While doing the modification I seem to have also modified the use of the left mouse key when clicking on a folder. The system now also prints the selected directory when clicking with the left mouse key on a folder. I note when I right click on the folder I can select open and list the directory to the video display. Some how there is an option which is second from the top in the window upon clicking with the right key which also looks like the same option in the "sent to " drop down window which does the new directory print function. Some how I managed to also put the print directory option in the left default position. I can live with this but I would like to correct the function if possible. Do you have a suggestion as to how I can find the left mouse key options when clicking on a folder. Thank you in advance for any suggestions you may be able to pass to me. R Borris
for Robert…
You probably changed your folder actions. Go back to that step and see what default action is set. It probably should be "open"
If I did follow the Microsoft site, how do I "hack the registry" to remove the search companion from starting?
Rachel - Try this: http://support.microsoft.com/kb/321186
It worked for me…
This is a great tool. Many people don't use or even know of the dos commands. At one time I was able to print directly from a DOS prompt just by typing print lpt1. Not any more. I have a lot of files I wanted backups for an archive and this was the perfect tool to an alternate of what was recommended to me which was to print screen and paste to a document. That would have taken waaaayyy to long.
Thank you very much for this information… it help me a lot!
what a silly trick… it puts/sends temp file directly to printer, without possibility to edit and then the printer prints that notepad file in "horse size" letters…
better to use FileGrab from http://www.pcmag.com/article2/0,2817,1161099,00.asp
Houston, I have a problem. Used the text above and made the batch file and it shows up as Print Directory Listings via a right click. So far, so good.
But.. if I have a directory open that does not have a subdirectory, invoking this print.bat file prints the window/system32 directory. If the directory I'd like to print has a subdirectory and I right click that subdirectory in the right pane of Win Explorer, it will print the right pane, not the directory selected. If I right click any directory in the left pane, I get the 37 pages of system32 directory.
Suggestions??
vista home premium
HP Pavilion dv7
This free utility called printfolder is the best. Check out the screenshot at http://no-nonsense-software.com/freeware/grabs/printfolder_grab.gif
The solution to this problem is covered in Microsoft Article ID 321186. This was a result of a bug in Windows XP which develops when the "Send To" Opeions are modified .
Exxxcellent! It's been a long while since a cute technical trick made me laugh with delight…;-) (especially the command-line use) And, it teaches tricks about "Send To", system variables, and Notepad as drivebys. Bravo
My problem is that my XP subdirctory is printed in old 128 character mode and not in UNICODE rendering my Greek language file names as jibberish. Any fix for this?
I use Print Directory to do this job easily…
Found here http://www.print-directory.com
Just wanted to let you know that with your instructions, I now have a print directory command in Explorer! One question though…how can you set up new page margins in that I have some long file names for comprehensive project that I am working on and would like for each of the file names to be on a continuous line.
TIA!
John
Sorry…meant SINGLE" line.
Quite good directory treeview tool called print directory not a freeware but affortable.
Here is good utility: Directory Report http://www.file-utilities.com
It can print reports in Unicode so Alex's Greek files will appear correctly
Is there a way it can be directed to print the sub-directories (using the dir /s) but only print the folders, not the files in each directory?
Great post. Where does it save the file to?
@Phil
The file is created in your temporary directory, but the file is deleted after it is printed. The file name is Listing.
To see where your temp directory is located, at the command prompt type:
echo %TEMP%
@echo on
dir /s %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
exit
For subdir this works for me. Cheers
I found an easy way to get a list of files in a directory while in Explorer to print to a printer connected to a USB (or the default) port. Just go to the DOS prompt and change to the directory of interest. Then type the following at the DOS promt: dir> directory_files.txt. This prints the output to a text file (directory_files.txt) in that directory. It can be opened and edited, if need be, and then printed. This works fine in Windows XP and is as simple as it gets.
Just bumping Sean's comment. I also need to print only folders not files. otherwise it's about 500 pages lol
@Sean & Ryan
Try this:
dir /ad /s
You can print the tree by using…
@echo off
tree /a %1 > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit
As a followup to Sean and Ryan and Jim, to print only the directories and not the files and directories, just type the following at the DOS promt:
dir> /ad > directory_files.txt. This prints the output to a text file (directory_files.txt). It can be opened and edited, if need be, and then printed. No need to write a batch file.
Usng the DOS prompt is fine but relieves the "burden" of running through the "cd" process.
I think this is neat and is nice ot see the use of "classic" command line.
Is there a way to pause the print process so that the printer option opens? I'd like to be able to select which printer the report goes to, ie hard copy or PDF. While I could write the files (by deleting the "del" command and printing manually, it would be easier to run it off, print it and then continue with the sub-routine to complete the deletion. Or am I just being greedy!
Thank you so much for these very understandable directions for how to print a directory,I have 2 problems, or I should say questions about this. I am running windows vista, & Had to enable the administrator account so I could log in as administrator to do this. Now the only way I can use my Print Directory listing is to log in as administrator not as owner (that is my usual log in) My 2nd problem is my lists that I use as an index is in numerical order, & I would like to print them that way. As it is set up now it starts with 1 then 10,100,1000,1001… & For the directory to do me any good I need it to be in normal numerical order 1,2,3,4… Please Email an answer to me if possible, & I am not a computer genius by any means, so if any changes can be made I would need the answer to be as explicit as the original directions, thank you so much for this great tool.
Anyone remember Tree View from back in the day? Well I work with 1,000+ Directories and I can't state how much this helps especially with updates. Thank you! Works perfectly for me.
Please Please!!!
Can someone send me a code to print the all directories, all subdirectories and all files in tree structure.
Thanks in advance.
Haritau
@Harit
To print everything, just substitute thie dir command in the article example
(dir %1 /-p /o:gn > "%temp%\Listing")
with the following command:
dir %1 /s /o:gn > "%temp%\Listing"
For some reason, in Windows 7, I cannot get /s to work for this. Still only shows the contents of the parent directory, does not display contents of sub-folders. Any ideas?
Code follows:
@echo off
dir /s %1 /-p /o:gn > "%temp%\Listing"
start /w notepad "%temp%\Listing"
exit
This one will open notepad with bare listings,
then print or save or export to word ,excel, etc.
@echo off
dir %1 /B /On /o:gn > "%temp%\Listing"
start notepad "%temp%\Listing"
exit
Using Windows 7 Pro
Script works fine from local C: drive, but will not list anything except volume info for usb drives. Using this batch file:
@echo off
dir %1 /-p /o:gn > "%temp%\Listing"
start /w textpad "%temp%\Listing"
del "%temp%\Listing"
exit
I hope this is still getting attention. Thanks in advance.
Bare bones… save a list of ONLY directories and sub-directories:
dir *. > /ad /s /b > yourfile.txt
I followed the microsoft article for windows 7 to print the files in a folder.
When I use 'Print Directory Listing' in the context menu I only get the list for the root directory, not for the folder selected.
If I shift and right click in the right hand side of Windows explorer and open a command prompt window and type 'printdir' (even without typing .bat at the end) I get the print of all the files in the folder, just what I want.
Why does it work when I run the Printdir.bat file in the command window but not if I run it from the context menu?? Help!
This purports to be free but it isn't (unless you only want 5 files and 2 subfolders from each folder - you are told on starting the program). I probably would have bought it if they had been upfront but I have now uninstalled it.
My previous comment applied to John's reference to "print directory". (I thought it would appear after his comment).
@Rob N: i don´t really have the answer to your question… but setting the pdf printer as default allows you to save the file as a pdf instead of printing…
@John:
Unicode name, not support!!!
I followed the directions listed here and now when I double-click a folder in Windows Explorer, it does not open the folder. How do I un-do what I did? Cheers!
I have Vista (Home version).
I found this site looking for a simple way of creating a list of all folders and subfolders (but NOT files) ,in effect a tree of C:
I can reach C: and use various Dir commands but can't get exactly what I wish.The Dos Tree command includes files which I wish to omit.
Any got an answer ?Thanks
Veblen
Found a neat little freeware utility at…
http://www.primeoption.com.au/FreewareYourDir.htm
It shows the Directory and sub-directories up to 10 levels deep.
Output to a CSV file (Use spreadsheet program to read it.
Also outputs the whole tree to an image - BMP, GIF, JPG, TIFF or WMF.
I tried the Printdir.bat method but not happy that I could not see how many pages I was going to print (I was interested in everything in C:\Program files - quite a lot…)
Having modified the batch file it stops at Notepad so I can see what the output is and choose whether to print it/save it/abandon it - and when I close Notepad it all disappears!
To modify the Printdir file just remove the /p instruction after notepad so that that line reads…
start /w notepad "%temp%\Listing"
It is now a very useful addition to my Send To commands.
Further to my previous message about the neat little freeware utility at…
http://www.primeoption.com.au/FreewareYourDir.htm
The Print Preview option is very useful as it shows how many pages it is going to take.
@Erin:
Erin, this happened to me as well (using XP)-does anyone have an answer to how to undo the print directory changes?
Thanks.
That was FREAKIN FANTASTIC! Forever, I've been wanting a simple way to accomplish this. Thanks
SOOO, I really need to save this list - so I can copy it into an EXCEL spreadsheet - was able to print it - but that doesn't solve my problem?
Please Help! Thanks
@Elaine:
Please read my comment posted on 24 December 2010, where I said…
Found a neat little freeware utility at…
http://www.primeoption.com.au/FreewareYourDir.htm
It shows the Directory and sub-directories up to 10 levels deep.
Output to a CSV file (Use spreadsheet program to read it).
Output to a CSV (Comma Separated Value) file, and import that into your spreadsheet program such as Excel.
Thanks John W - will try that next
@Watching The Net: Where does the 'ls' fit into the Printdir.bat script? do i have to modify the script elsewhere?
@echo off
dir [HERE?] %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit
The link http://www.primeoption.com.au/FreewareYourDir.htm seems to be broken…
Can anyone help with this?
Thanks!
Hi Curtis,
You're right, that link does appear to be broken. Luckily, YourDir is such a popular little freeware utility that lots of other sites have it. Try one of these…
http://yourdir.en.softonic.com/
http://download.cnet.com/YourDir/3000-2248_4-10336832.html
http://www.softpedia.com/get/Others/Miscellaneous/Your-Dir.shtml
Best wishes,
This sucks ! It printed 44 pages without notifying me that its going to do that !
George,
You should have read my post sent on 24 Dec 2010, which included 2 solutions. For simplicity I repeat my previous post below.
- - - - - - - - - - - - - - - - - - - - - - -
I tried the Printdir.bat method but not happy that I could not see how many pages I was going to print (I was interested in everything in C:\Program files – quite a lot…)
Having modified the batch file it stops at Notepad so I can see what the output is and choose whether to print it/save it/abandon it – and when I close Notepad it all disappears!
To modify the Printdir file just remove the /p instruction after notepad so that that line reads…
start /w notepad "%temp%\Listing"
It is now a very useful addition to my Send To commands.
Further to my previous message about the neat little freeware utility at…
http://www.primeoption.com.au/FreewareYourDir.htm [Link working again 09-04-2011]
The Print Preview option is very useful as it shows how many pages it is going to take.
Super helpful post. Greatly appreciate the help.
Thanks for http://www.primeoption.com.au/FreewareYourDir.htm ! Very helpful.
Excellent use of the basics… i've tried nearly every freeware program out there and this simple batch file does exactly what i've always wanted the programs to do..
Thanks for the info…
In vista when I enter %appdata%\microsoft\windows\sendto, I get to the sendto folder, but when I right click, my only choices are "folder" or "briefcase". Shortcut isn't one of my choices. What gives?
Program works fine except when I plug in my MP3 player via USB port and want to print the directory of what's on my player. It shows up as a drive, but won't let me print the directory. Either there is no "Send To" shown when I right-click or I'm told I don;t have administrative rights (it's my home computer and no one else uses it). Any suggestions? Thanks?
Thank you for a very useful program. I learned several things with these instructions.
Thanks! This was very helpful and super easy to follow!
Thanks a lot for this! I didn't much like it when it just sent everything straight to the printer, but I found, in the comments, how to output to Notepad, and that is just perfect. Much gratitude to everyone involved.
This works great for me! I was able to list all of my music files and save them as a text file.
@echo off
dir %1 /-p/s /o:gn > "%temp%\Listing"
start /w notepad "%temp%\Listing"
del "%temp%\Listing"
exit
Excellent article, thank you very much for creating this! I now can create a listing of all the files I put on a tape backup.
I find that the Tree command works well too.
Might it more useful for sub directories and files in the sub directories (/F)
It also Prints out nicely.
@echo off
tree %1 /F /A > "%temp%\Listing.txt"
start /w notepad /p "%temp%\Listing.txt"
del "%temp%\Listing.txt"
exit
enough is to write in CMD following :
dir /S > filename.txt
you have directory tree with subdir's
enjoy
thank you for the how to print directory, now i want to see if i duplicate that and print to excel file instead the printer, my directory has 23 pages. i think it will be more easyer to work with excel file than 23 papers, thank you very much,
mean whil i will search the net to find excel way before i do it my self, i am lazy, thank you
Faiz,
Search the net and you will find a neat little freeware utility called YourDir that will output the results to a CSV file. YourDir shows the Directory and sub-directories up to 10 levels deep.
Note: CSV (Comma Separated Value) files can be read by most spreadsheet programs including Excel and can also be read by most database programs.
YourDir is such a popular little freeware utility that lots of sites have it.
Try one of these…
http://www.primeoption.com.au/FreewareYourDir.htm
http://yourdir.en.softonic.com/
http://download.cnet.com/YourDir/3000-2248_4-10336832.html
http://www.softpedia.com/get/Others/Miscellaneous/Your-Dir.shtml
did that, but needed to list mp3 title author etc. so found this http://www.krksoft.com (directory lister)
@Trinity:
The krksoft directory lister is free for 30 days trial, thereafter US $29 (about 18 GBP on 17 SEP 2012)
I haven't done this in a long time, but you used to be able to use
dir %1 > prn
(or in your example)
dir %1 /-p /o:gn > PRN
Which worked in Windows 9x and even XP.
However, that dumps things to LTP1 and while there used to be a way to get MS-DOS to use something else, I don't have a clue how to do that in Windows 7. If you're using a USB printer or a network printer it probably won't work, but if you have a printer connected to parallel port 1 it will still work.
I believe you have to set up your USB printer for MS-DOS programs for this to work.
The benefit is you can skip the temp file and starting Notepad.
@slickrcbd:
Search this list for "John W" and you will see several of my solutions to your problem. Better still, earch the net and you will find a neat little freeware utility called YourDir that will output the results to a CSV file or an image of your directory structure. YourDir shows the Directory and sub-directories up to 10 levels deep.
Note: CSV (Comma Separated Value) files can be read by most spreadsheet programs including Excel and can also be read by most database programs.
YourDir is such a popular little freeware utility that lots of sites have it.
Try one of these…
http://www.primeoption.com.au/FreewareYourDir.htm
http://yourdir.en.softonic.com/
http://download.cnet.com/YourDir/3000-2248_4-10336832.html
http://www.softpedia.com/get/Others/Miscellaneous/Your-Dir.shtml
YourDir is a very basic Windows program that will run on any version of Windows up to Windows7 (which I have just tested).
Hope this helps,
John
Prior to upgrading to Win7 Pro from XP Pro I used a neat little program called Tree Print. Originally came from PC Magazine (tpsetup.exe Installer). No matter what I try it will no longer work in Win7. Tree Print would print or save to a file; an unlimited tree structure of many folders or an entire disk.
Do you know of a Win7 compatible program currently that will do the same? I use the info provided by the program to have a searchable database of files burned on to my library of cd/dvd listings. Prior to burning the DVD I would embed the text file in the DVD and one in my searchable database for searching as needed.
@Kuma Bear:
Hi Kuma,
Immediately above your post is my post about YourDir. YourDir will do everything that your require and works in Windows7 and I've just test tested it in Windows8 - no problems.
See my post above yours for how to get YourDir.
Best wishes,
John
Fine way of explaining, and pleasant article to get facts about my presentation subject, which i am going to deliver in school.|
THANK YOU THANK YOU THANK YOU. I figured it out pretty quickly for a novice, due to your information.