Create a text file of the contents of a directory in Windows Explorer
Note: Tested on the 2 October 2007 using Windows XP Professional SP2.
Tip: The following guide will show how to output the contents of a directory to a text file for saving, printing or editing.
Method 1 - Using a batch file to create the text file:
- Create a new file in a text editor (i.e. open Notepad)

- Insert the following text into the file:
- dir /a /b /-p /o:gen >C:\WINDOWS\Temp\file_list.txt
- start notepad C:\WINDOWS\Temp\file_list.txt

- Save the file as File List Generator.bat
- To show the contents of a directory (folder) in a text file, simply copy or move the File List Generator.bat file into the folder where you want the contents printed and double-click the file.
This will save a text file with the contents of the folder and then open it in Notepad.
From here you can edit, format and print the contents.
Modifying the output of the text file:
In the above example the text file simply created a list of the files and folders within the directory. It is also possible to output other information about the directory such as date and time stamps, file sizes and drive information.
- Create a new file in a text editor (i.e. open Notepad)
- Insert the following text into the file:
- dir /a /b /-p /o:gen >C:\WINDOWS\Temp\file_list_full.txt
- start notepad C:\WINDOWS\Temp\file_list_full.txt
- Save the file as File List Generator.bat
Note: If you have any problems it is usually caused by this part of the code:
- C:\WINDOWS\Temp\
Make sure this directory exists and that you have permissions to read/write or, adjust the path to point to another folder. For instance:
- dir /a /b /-p /o:gen >C:\file_list.txt
- start notepad C:\file_list.txt
The above code would save the file to the top level of the C drive.
Method 2 - Using the command line to create the text file:
- Click Start, then click Run...
- Type cmd into the entry box and click OK
- From the windows command line, navigate to the directory/folder that you want to save to the text file.
Tip: For example:
- Type d: to move to another drive (d)
- Type cd \ to go to the root of the drive
- Type cd \some\directory to go to a specific directory
- To output the contents, type one of the following:
- dir /b >some-file.txt
- Will output all of the contents (files and folders)
- dir /b *. >some-file.txt
- Will output only the folders
- Type exit to close the command line.
A text file (some-file.txt) will be saved in the same directory from where the command was made.
Go back to the How-to Guides main page.