Create a text file of the contents of a directory in Windows Explorer
Tested on the 2nd October 2007 using Windows XP Professional SP2
Note: 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
- dir /a /b /-p /o:gen >C:\WINDOWS\Temp\file_list_full.txt
- Save the file as File List Generator [full].bat
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 Run...
- Type 'cmd' into the entry box and click OK
- From the windows command line, navigate to the folder that is to be saved to the text file. 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 the directory required
- To output all the contents (files and folders), type 'dir /b >some-file.txt'
- To output only folders, type 'dir /b *. >some-file.txt'
- 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.
Web accessibility:
A A A AFor more information about these functions and how to use them, view the web accessibility page.

