How To Print A Directory Tree From Windows Explorer

84

winlogo.jpgDo 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:
@echo off
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.

winprintdirtree2.png

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.

winprintdirtree3.png

  • Type Print Directory Listing in the "Type a name for this shortcut" and click Finish.

winprintdirtree4.png

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.

winprintdirtree5.png

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 Leave a Comment

June 28, 2008

Gerard @ 8:04 pm #

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!

Gerard @ 8:16 pm #

Just one other thing,
This does not print sub folders. is there a way of doing this without expanding?

August 6, 2008

Charles @ 5:51 pm #

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.

August 7, 2008

Charles @ 12:39 pm #

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

August 8, 2008
September 14, 2008

Barry @ 5:07 pm #

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!!

September 15, 2008
October 8, 2008

bill @ 7:48 am #

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?

January 6, 2009

Robert Borris @ 12:32 pm #

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

April 21, 2009

Toby @ 1:28 pm #

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"

May 6, 2009

Rachel @ 10:34 am #

If I did follow the Microsoft site, how do I "hack the registry" to remove the search companion from starting?

Margie @ 3:32 pm #

Rachel – Try this: http://support.microsoft.com/kb/321186

It worked for me…

June 18, 2009

Vera Fernandes @ 9:41 am #

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.

July 5, 2009

John @ 4:46 pm #

Thank you very much for this information… it help me a lot!

July 18, 2009

geras.galas @ 8:47 am #

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…

geras.galas @ 8:49 am #

July 21, 2009

Mike @ 10:08 am #

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

July 29, 2009

Dronacharya @ 9:08 pm #

This free utility called printfolder is the best. Check out the screenshot at http://no-nonsense-software.com/freeware/grabs/printfolder_grab.gif

July 31, 2009

Robert Borris @ 3:45 pm #

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 .

August 3, 2009

james triplett @ 12:33 pm #

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

August 25, 2009

Alex Dodis @ 5:19 am #

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?

September 10, 2009

John @ 5:48 pm #

I use Print Directory to do this job easily…

John @ 5:48 pm #

September 11, 2009

John Couch @ 3:44 pm #

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

John Couch @ 3:45 pm #

Sorry…meant SINGLE" line.

September 16, 2009

Adam jean @ 3:44 am #

Quite good directory treeview tool called print directory not a freeware but affortable.

October 8, 2009

Binaryman @ 11:20 am #

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

November 9, 2009

Sean @ 12:41 pm #

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?

November 16, 2009

Phil @ 6:29 pm #

Great post. Where does it save the file to?

November 17, 2009
December 26, 2009

Danny @ 2:15 pm #

@echo on
dir /s %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
exit

For subdir this works for me. Cheers

January 10, 2010

Ron Guidotti @ 12:09 am #

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.

January 12, 2010

Ryan @ 11:38 pm #

Just bumping Sean's comment. I also need to print only folders not files. otherwise it's about 500 pages lol

January 13, 2010
January 27, 2010

Jim @ 3:30 pm #

You can print the tree by using…

@echo off
tree /a %1 > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit

Ron Guidotti @ 6:46 pm #

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.

March 22, 2010

Rob N @ 2:26 am #

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!

March 27, 2010

Ralph Hansen @ 10:24 am #

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.

March 28, 2010

Allen S. @ 1:37 am #

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.

April 22, 2010

Harit @ 12:54 am #

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

May 27, 2010

Other Sean @ 2:55 pm #

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

June 9, 2010

Con @ 8:17 pm #

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

July 27, 2010

Cold1s @ 3:43 pm #

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.

August 22, 2010

alz @ 2:17 pm #

Bare bones… save a list of ONLY directories and sub-directories:

dir *. > /ad /s /b > yourfile.txt

August 25, 2010

Phil Wallace @ 4:45 pm #

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!

September 11, 2010

Dani @ 12:33 pm #

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.

Dani @ 12:36 pm #

My previous comment applied to John's reference to "print directory". (I thought it would appear after his comment).

September 17, 2010

Jean-Baptiste @ 10:59 am #

@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…

November 9, 2010

Dash Ali @ 3:06 pm #

@John:
Unicode name, not support!!!

November 29, 2010

Erin @ 2:47 pm #

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!

December 10, 2010

veblen @ 12:17 pm #

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

December 24, 2010

John W @ 2:21 pm #

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.

John W @ 2:46 pm #

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.

January 6, 2011

Janet @ 12:48 pm #

@Erin:

Erin, this happened to me as well (using XP)–does anyone have an answer to how to undo the print directory changes?
Thanks.

February 25, 2011

Jose @ 5:42 pm #

That was FREAKIN FANTASTIC! Forever, I've been wanting a simple way to accomplish this. Thanks

March 14, 2011

Elaine @ 11:25 am #

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

John W @ 12:24 pm #

@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.

Elaine @ 12:28 pm #

Thanks John W – will try that next

April 1, 2011

Joe Cain @ 11:47 am #

@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

April 22, 2011

Curtis @ 2:18 pm #

The link http://www.primeoption.com.au/FreewareYourDir.htm seems to be broken…
Can anyone help with this?

Thanks!

John W @ 2:47 pm #

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,

May 9, 2011

George @ 9:09 am #

This sucks ! It printed 44 pages without notifying me that its going to do that !

John W @ 10:57 am #

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.

June 30, 2011

Joe @ 1:37 pm #

Super helpful post. Greatly appreciate the help.

July 2, 2011

MJ @ 6:58 pm #

July 27, 2011

Dave @ 10:40 am #

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…

August 9, 2011

Hugh Gerth @ 10:46 am #

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?

September 26, 2011

Marty @ 6:30 pm #

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?

November 7, 2011

Carol Bales @ 10:10 am #

Thank you for a very useful program. I learned several things with these instructions.

January 4, 2012

Amy Henry @ 10:44 am #

Thanks! This was very helpful and super easy to follow!

January 7, 2012

Curtiss H. @ 11:00 am #

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.

January 15, 2012

Limey @ 1:06 pm #

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

February 2, 2012

Tri @ 6:07 pm #

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.

February 17, 2012

Justin @ 8:51 am #

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

February 29, 2012

maciej @ 2:24 am #

enough is to write in CMD following :

dir /S > filename.txt

you have directory tree with subdir's

enjoy

March 13, 2012

faiz jubran @ 8:47 pm #

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

March 14, 2012

John W @ 1:10 am #

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

September 16, 2012

Trinity @ 1:34 pm #

did that, but needed to list mp3 title author etc. so found this http://www.krksoft.com (directory lister)

September 17, 2012

John W @ 11:41 am #

@Trinity:

The krksoft directory lister is free for 30 days trial, thereafter US $29 (about 18 GBP on 17 SEP 2012)

January 14, 2014

slickrcbd @ 2:00 pm #

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.

John W @ 4:59 pm #

@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

Leave a Comment

Fields marked by an asterisk (*) are required.

Subscribe without commenting