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, using Google Chrome, Firefox web browser, or SysExporter.
Different Methods to Print Directory Listing
Print Directory Contents using Command Prompt
- Open the folder for which you want to print the directory listing.
- Type
cmd.exe
in the address bar to open Command Prompt in the current folder. - 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:
- 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
- Save the file as
print_dir.reg
and double-clickprint_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:
- 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
- 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.
Print Directory Contents using SysExporter
Nirsoft’s SysExporter allows you to grab the data stored in standard list-views, tree-views, list boxes, and combo boxes from almost any application running on your system, and export it to text, HTML or XML file.
- Open the folder for which you want to export the directory list. For example, here’s my Downloads directory:
- Enable the required columns and sort items accordingly.
- Download SysExporter.
- Run SysExporter. If the window you want to capture is running elevated, then start SysExporter as administrator.
- In SysExporter, click on the crosshair icon on the toolbar and drop it on the folder window whose contents you want to capture.
(This shows you the list of items in that folder, exactly as you see in the folder view.)
- In the lower pane, select all the entries (Ctrl + A)
- Press Ctrl + C. Or, from the “Items” menu, select Copy Selected Items (Tab Delimited)
- Open Notepad and paste the text from the clipboard.
- Save the Notepad document.
You can also open the exported tab-delimited file using Microsoft Excel and apply the required fonts and formatting with column headers.
Alternatively, you can export the listing to a HTML file. To do so, click “HTML Report (All items)” from the “Items” menu.
SysExporter can be very useful especially when you want to capture the metadata columns (e.g., for a Music or Videos folder) in a folder view and export the listing to a file.
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!
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
@Petra: The info still holds good for Chrome Version 97.0.4692.99 – January 2022. The Firefox part in this post has been updated for the current version (96.0.3, as of the revision).