Microsoft

List Directory Contents To A Printable and Readable Txt File [How-To]

image
Need to know exactly what’s on a computer and want to look at it from a glance or a printed directory version?  The command prompt (DOS CMD) has been existent since the beginning of Windows, so this groovy trick will work no matter if you’re using the latest Windows 7, Windows XP, or even Windows 98.  The best part is that it auto-generates the entire list for you.

 

How To Automatically Create A Text Document Directory Listing Of Any Folder In Windows

 

1. Click the Windows Start Menu Orb and Type in cmd.  Once the program link appears, Right-Click cmd.exe and Select Run as administrator.

open command prompt in administrator mode

 

2. In the command prompt that is displayed, Navigate to the correct folder you want.  Navigation is relatively simple, just type “cd” (change directory) and then the local location of the folder on your computer.  For example, if I wanted to go to c:Program Files, I would just Type:

cd c:program files

use cd in command prompt to change directory

 

3. Once command prompt is at the folder you want a directory of Type in the following:

dir /s> Directory.txt

Tip:  Add /b like in the screenshot below if you don’t need file details such as size, or date to be included.

use dir /b /s > directory.txt to output a dir query to a text file

 

The Result

A file named Directory.txt is created and placed in the same folder where you just queried a directory.

a directory.txt file is created on your windows system

 

Inside of Directory.txt will be a complete list of every file within the queried location.  In this example I have a HUGE list of every folder and file in c:program files and the list gets even bigger as it contains every content of every folder within every folder and each file in those.  In this way, you can view every single file from any parent location in Windows in an organized and printable format.

a complete list of all contents in a directory including a sub-folder and sub-files

 

The Tree Alternative

If you are more of a visual person, then the tree format may better suit your needs.  This command works similar to the above one.

Just follow the above instructions, but at Step #3 rather than typing “dir /s> Directory.txt” instead Type:

tree> Tree.txt /A /F

using the tree command in windows 7

 

The Tree Result

A Tree.txt file will be generated and placed in the same directory.  This Tree format will display the same information as the other Directory, but it will be organized similarly to the way keys show up in the Windows Registry Editor.  From here you can print or email the organized content list quickly. Groovy eh?

a printable tree of every file on your system in the specified directory

 

The Prompt (DOS) Commands Explained

CommandSub CommandExplanation
cdAka change directory, used for basic navigation in DOS.
dirDisplays all contents of the current directory
/sWhen added after dir will display subdirectory contents
/bMakes dir display only basic or “bare” file information
>> Is an interjectory value that forces command output to an external file or location. Useful for any query.
treeA graphic version of dir
/aProvides ASCII graphics
/fMakes tree display file names

 

Questions, Thoughts?  Post a comment below and check out the free groovyPost RSS feed for daily tech-related tips, how-to, and news.


8 Comments

8 Comments

  1. Cliff  

    Anyone know how to do this on a Mac?

    • @Cliff
      On a Mac it’s relatively similar, but you use the “ls” command instead.
      Example:
      ls> Directory.txt

  2. This is a good tip, but there is a terrific free utility that is much better for tracking and finding files: It’s called Everything by VoidTools. http://www.voidtools.com/download.php

    I am in no affiliated with VoidTools, just a very happy user. I used to use tricks like your article explains, but now with EveryThing you can quickly find (by pattern) any file on your system _very_ quickly.
    rp

    • Thanks Roger. Will check it out. If it’s work a write-up perhaps we will do a review on it (unless you want to do a quick writeup?). Thnx and welcome to groovyPost!

  3. Ted Levinson  

    Here are the REG keys to make this a right-click mouse function.

    HKCR,”Drive\Shell\Command Prompt Here\command”,,,”%11%\cmd.exe /k cd “”%1″””
    HKCR,”Directory\Shell\Command Prompt Here\command”,,,”%11%\cmd.exe /k cd “”%1″”” ; Add “command-prompt-here” functionality when right-clicking a directory
    HKCR,”Folder\Shell\List Contents to text file\command”,,,”%11%\cmd.exe /C DIR “”%1″” /B /O /S>””%1″”””_contents list.txt”””

  4. Another fine post, well researched and written. You should be proud!

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top