Print Directory Contents to a File

Why?
A friend asked me if there was a quick way to simply right-click on a folder in Windows Explorer and it would generate a text file with the contents of the directory he right-clicked.

What?
We can do this by adding an entry to the context menu (when you right-click on an object). The following is a method of adding this as a single command similar to how we add the "Command prompt from here" option (now built-in to Windows 7). I added this option for him in Windows 7 Ultimate using the system registry (see "How: for Windows 7" below).
copyraw
-- yield

a_subfolder_in_this_folder
a_file_in_this_folder.txt
another_file_in_this_folder.doc
  1.  -- yield 
  2.   
  3.  a_subfolder_in_this_folder 
  4.  a_file_in_this_folder.txt 
  5.  another_file_in_this_folder.doc 

How?
For Windows XP:
  1. Open an instance of Windows Explorer and click on "Tools"
  2. Select "Folder Options..."
    Open Windows Explorer, Click on Tools, Click on Folder Options...
  3. Select the "(NONE) Folder" option
  4. Click on "Advanced"
    Select (NONE) Folder, Click on Advanced
  5. Click on "New..."
    Click on New...
  6. Enter the New Action as per the following:
    1. Action: - Give the action name a memorable name (eg. "Print Directory Contents To File")
    2. Application: - Type the following c:\windows\system32\cmd.exe /c "dir %L /b > %L\directory_printout.txt"

    Add Action and Application used to perform action
  7. OK and close all open window dialogs
  8. TEST: Open an instance of Windows Explorer, Right-click on a folder and select the action you named in step 6.
    TEST IT
For Windows 7:
  1. Open the system registry (Start > Run... > Type "REGEDIT" > OK)
  2. Navigate to My Computer\HKEY_CLASSES_ROOT\Folder\shell
  3. Create a new key with the action name (eg. "Print Directory Contents To File" - replace spaces with underscores if you are unsure this will work)
  4. Add a key to this one called "command"
  5. Under the "command" key, there should be a new string value called "(Default)". If there isn't create a New "String Value", name it "(Default)"
  6. Double-click this string value and type the following c:\windows\system32\cmd.exe /c "dir %L /b > %L\directory_printout.txt" (including the double-quotes)
    RegEdit Keys, Strings and Values
  7. TEST: Open an instance of Windows Explorer, Right-click on a folder and select the action.

Additional Notes:
  1. This outputs the contents to a text file called "directory_printout.txt". This file will be stored in the folder that you asked to list.
  2. Instead of C:\windows\system32\cmd.exe, I could have used %Comspec% or even %windir%\system32\cmd.exe but with some group policies, you will get an "access denied" message. If you don't have a C:\windows folder, then find your "cmd.exe" program and change the path in the above instructions accordingly.
Category: Windows OS :: Article: 420

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.