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:

Step 1:

Create a new file in a text editor (i.e. open Notepad)

New notepad file

Step 2:

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
Notepad file with inserted text

Step 3:

Save the file as File List Generator.bat

Step 4:

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.

Step 1:

Create a new file in a text editor (i.e. open Notepad)

Step 2:

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

Step 3:

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:

Step 1:

Click Start, then click Run...

Step 2:

Type cmd into the entry box and click OK

Step 3:

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 the directory required

Step 3:

To output all the contents (files and folders), type:

dir /b >some-file.txt

To output only folders, type:

dir /b *. >some-file.txt

Step 4:

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.

Search

Starter website

Offering small businesses and individual users the opportunity to have their own website on the internet, our 'starter websites' are available for only £150.

new site offer

To find out more and to see an example of the type of site offered, view our example starter website page.