DOS command to list files in a directory into a text file

Looking for DOS command to create file listing of a folder and its sub-folders into a text file? Here are the simple steps.

Before using the commands, do below steps

  1. Open Command Prompt
  2. Goto the folder path from where you want to list the files. 
  3. Run below commands

In below examples, C:\Main-Folder\Folder> is the folder path

dir > is the command

C:\Main-Folder\list.txt is the path for output text file. The text file will be created automatically, if it doesn’t exist.

Case 1:  DOS command to list files in a folder

 

Command :  dir >

Example:

file-listing-folder-Dos-command

 

 

 

Output: list.txt file

DOS-command-listing-files-folders-output-text-file

Case 2: DOS command to list files in folder and its sub-folders

 

DOS Command:  dir /s >

Example:

Dos-command-file-listing-text-file

 

 

 

Output:

listing-files-folder-sub-folder-text-file-example

Case 3: Listing only specific type of files

Suppose if you want to list only .txt files, then use below command.

dir /s *.txt >

Example:

Dos-command-specific-file-listing-text-file

 

 

 

 

Output:

DOS-command-listing-specific-files-text-file

 

Notes:

1.If you have spaces in file name, then you will see “File Not Found” error. Don’t worry, just ignore that. Text file and file listing will be created.

error-file-listing-dos-windows