PDQ Library:  Make a List of Files in a Folder

You must already know how to use batch commands to use this page. I accept
no responsibility for any accidents you have using batch commands.

First you will create a Windows Batch program using a text editor (Notepad). Copy the batch program below using the "select" button and copying it into your text file. You must edit the paths in the sample batch program to match the location of your particular folder. You must not split long lines.

Edit C:\****\ to match the path of the folder you want to list. Edit USER to your "user name". This batch program will create a text file called LIST.txt in the Documents folder. The second time you run this batch program, the file will be replaced, so rename it if you want to keep it. (See batch-date.html to learn how to add today's date to a file name.)

Click to select text in box   Select text and type CTRL+C keys to copy it.
ECHO Folder-List.bat
REM Remove /s in command below to NOT list subfolders
DIR C:\****\ /s /ad /b /on > C:\Users\USER\Documents\LIST.txt
ECHO done...

The only required command line starts with "DIR". Here is an explanation of the switches used in that command:

  • /s Includes files in all subdirectories. Default lists top level of the folder only.
  • /ad Displays files with specified attributes: d = directories
  • /b Uses bare format (no heading information or summary).
  • /on Sort list ordered by n = name
  • > Create/overwrite a file
  • >> will append to an existing file.
  •     Quotes are required around a path containing a space.

Example 2: Listing all files on a DVD

This command creates a list of all files on a DVD drive D: and stores it in a text file DVD_XXXX.txt in the My Documents folder of a user called Cathy:

dir E:\ /ogn-d/s > "C:\Users\Cathy\My Documents\DVD_XXXX.txt"
TOP back