Site icon Winhelponline

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.

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

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

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:

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

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

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

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

Add the following to the Style Sheet Editor.

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

Then remove the following lines from “Inline Style Sheet #1” in the Style Editor window.

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

.dir ,
.symlink ,
.file {
margin-inline-start: 20px;
}

Also, remove the following styles from the DirListing.css

.dir::before {
content: url(chrome://global/skin/dirListing/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.

Close Developer Tools (Ctrl + Shift + i).

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

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.

Exit mobile version