How To Print A Directory Tree From Windows Explorer

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!

Filed under Windows Tips, Windows Vista Tips by

Comment

Comments on How To Print A Directory Tree From Windows Explorer »

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?

Watching The Net @ 10:34 pm

@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

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.

Watching The Net @ 8:47 pm

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

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

Watching The Net @ 11:01 am

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

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

Watching The Net @ 9:20 am

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

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.

Leave a Comment

Subscribe without commenting