How to Print Directory Contents Using Different Methods

You can copy folder contents by selecting all items in a folder, pressing Shift key and clicking the Copy as Path command in the right-click menu. Then open Notepad or any other text editor and paste the contents from the clipboard.

print directory contents in windows - copy as path

But if you need to print the directory list for the current folder and subfolders recursively, you need a different approach. This article discusses different ways to list folder contents including the Windows command-line method, or using Google Chrome, or Firefox web browser.

Print Directory Contents using Command Prompt

  1. Open the folder for which you want to print the directory listing.
  2. Type cmd.exe in the address bar to open Command Prompt in the current folder.
  3. Type the following command and press ENTER:
    dir /o:gn

    This shows the list of files and folders in that directory.

    Copy to clipboard

    To output the directory contents list to the clipboard, use the following command:

    dir /o:gn | clip

    Then, to view the output, open Notepad and paste the contents from the clipboard.
    print directory contents in windows

    Print the output to file

    Alternately, you can also write the output directly to the %temp%\printdir.txt temporary file, using the following command-line:

    dir /o:gn > "%temp%\printdir.txt"

    Then, open the %temp%\printdir.txt file using Notepad.

    To list the directory contents recursively (including subfolders), use the /s argument:

    dir /o:gn /s > "%temp%\printdir.txt"

Add Print Directory to the right-click menu

To add the Print Directory List command to the right-click menu, follow these steps:

  1. Open Notepad, and copy the following text to Notepad:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\printdir]
    @="Print Directory Contents"
    
    [HKEY_CLASSES_ROOT\Directory\shell\printdir\command]
    @=hex(2):63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,63,00,20,00,64,\
    00,69,00,72,00,20,00,2f,00,2d,00,70,00,20,00,2f,00,6f,00,3a,00,67,00,6e,00,\
    20,00,22,00,25,00,31,00,22,00,3e,00,25,00,74,00,65,00,6d,00,70,00,25,00,5c,\
    00,70,00,72,00,69,00,6e,00,74,00,64,00,69,00,72,00,2e,00,74,00,78,00,74,00,\
    20,00,26,00,26,00,20,00,73,00,74,00,61,00,72,00,74,00,20,00,6e,00,6f,00,74,\
    00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,25,00,74,00,65,00,\
    6d,00,70,00,25,00,5c,00,70,00,72,00,69,00,6e,00,74,00,64,00,69,00,72,00,2e,\
    00,74,00,78,00,74,00,00,00
  2. Save the file as print_dir.reg and double-click print_dir.reg to run it.

This adds a Print Directory Contents command to the right-click menu for folders, which when clicked, shows the directory contents using Notepad automatically.

print directory contents in windows

Note: The hex code above translates to the following command:
cmd.exe /c dir /-p /o:gn "%1">%temp%\printdir.txt && start notepad.exe %temp%\printdir.txt

The command is created in the following registry key:

HKEY_CLASSES_ROOT\Directory\shell\printdir\command

print directory contents in windows

Sample output when you click Print Directory Contents:

Volume in drive D has no label.
Volume Serial Number is F4AC-F4D1

Directory of D:\Websites\uploads\2019\02

05/20/2019 12:18 AM <DIR> .
05/20/2019 12:18 AM <DIR> ..
05/20/2019 12:18 AM 13,751 800f081f-0x20003.png
02/24/2019 10:47 AM 39,751 set-pin-error-0x80090016.png
02/23/2019 07:46 PM 106,081 w10-default.zip
05/20/2019 12:18 AM 11,812 w10-disable-developer-mode.png
02/23/2019 07:46 PM 10,505 w10-userprofile-failed-sign-in.png
5 File(s) 181,900 bytes
2 Dir(s) 274,388,795,392 bytes free

Print directory listing in Tree format

To print the directory contents in a tree format, use this command-line syntax:

TREE [drive:][path] [/F] [/A]

/F Display the names of the files in each folder.
/A Use ASCII instead of extended characters.

The TREE command always lists the items in the current folder and subfolders recursively. But the tree output wouldn’t have any details other than the file and folder names.

Example:

tree /f /a d:\backup\tweaks | clip

Sample output of the Tree command:

print directory contents in windows

Add “Print Directory Contents (Tree)” to the right-click menu

To add Print Directory Contents (Tree) in the right-click menu for folders:

  1. Using Notepad, make a .reg file from the following contents:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\printdirtree]
    @="Print Directory Contents (Tree)"
    
    [HKEY_CLASSES_ROOT\Directory\shell\printdirtree\command]
    @=hex(2):63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,63,00,20,00,74,\
    00,72,00,65,00,65,00,20,00,2f,00,61,00,20,00,2f,00,66,00,20,00,22,00,25,00,\
    31,00,22,00,20,00,3e,00,25,00,74,00,65,00,6d,00,70,00,25,00,5c,00,70,00,72,\
    00,69,00,6e,00,74,00,64,00,69,00,72,00,2e,00,74,00,78,00,74,00,20,00,26,00,\
    26,00,20,00,73,00,74,00,61,00,72,00,74,00,20,00,6e,00,6f,00,74,00,65,00,70,\
    00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,25,00,74,00,65,00,6d,00,70,00,\
    25,00,5c,00,70,00,72,00,69,00,6e,00,74,00,64,00,69,00,72,00,2e,00,74,00,78,\
    00,74,00,00,00
  2. Run the .reg file by double-clicking on it.
The hex code above translates to the following command-line:
cmd.exe /c tree /a /f "%1" >%temp%\printdir.txt && start notepad.exe %temp%\printdir.txt

This adds the Print Directory Contents (Tree) command to the right-click menu for folders.

print directory contents in windows - tree command

Print Directory Contents using Google Chrome

Open Google Chrome, type the folder path in the address bar and press ENTER. This shows the folder contents, sorted by Name with folders on top. You can sort it as you’d like – by Size or Date Modified column – thanks to Chrome’s sortTable JavaScript function.

print directory contents chrome firefox

While the file and folder icons are shown in the normal view, they won’t be outputted when you print directory contents to a physical printer or output to a file.

print directory contents chrome firefox

Print Directory Contents using Mozilla Firefox

In Mozilla Firefox, directory listings are shown in a better way, with a better style sheet.



Click the Name column header to sort the listing by name with folders on top.

print directory contents chrome firefox

The file and folders icons look neat, but you most likely don’t want to see them in print. Firefox’s print preview dialog would show the icon for every file listed, but not for folders.

print directory contents chrome firefox

You can apply your own styling to the directory contents page, and remove the file/folder icons from being printed.

Add or Remove Custom Styles

Launch the Firefox Developer Tools / Inspector by pressing Shift + F7. Alternately, use F12 (or Ctrl + Shift + i) and click “Style Editor”.

print directory contents chrome firefox

Add the following to the Style Sheet Editor.

.dir::after { content: "/" }
img { display:none }

Then remove the following lines in the Style Editor window, and close Developer Tools (Ctrl + Shift + i).

.dir::before {
content: url(resource://gre/res/html/folder.png);
}

Doing so would hide the file and folder icons to prevent them from being printed. Also, to easily differentiate between files and folders, the custom stylesheet code adds a trailing forward slash (“/”) after the directory name. Chrome, on the other hand, does this by default.

So here is how the print preview looks like, and so would the final output to printer or a PDF file.

print directory contents chrome firefox

print directory contents chrome firefox

Note: In Internet Explorer or Microsoft Edge, when you type a directory path the folder window is launched rather than the browser rendering the folder contents.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

About the author

Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and he has been a Microsoft Most Valuable Professional (MVP) for 10 consecutive years from 2003 to 2012.

1 thought on “How to Print Directory Contents Using Different Methods”

  1. I am very interested to learn Ramesh if your previous findings still stand in Chrome Windows 10 in printing off file directories. Yours to date seem to make the only sense but just wondering if there has been any advancement. Thank you for the hard work you do

    Reply

Leave a Comment