Create a text list of files in a folder with cmd

How to create a list of all Windows files contained in a folder and insert it into a text file with a cmd command? It pretty easy and it is the combination of two MS-DOS scripts, you need to add in the command to redirect the output of the dir batch comand.

1. How to create a list of the files in a folder with CMD?

For example, to list the files and folders from a specific directory recursively, use the dir command:

dir /s

2. List all the files recursively in subfolders

Or this variant to display explicitly the content of a folder using explicitly the full path. Per default, it will display various informations like the date and time modification, the type, if it is a directory or a file and the size.

dir /s C:\Folder\SubFolder 

3. Create a text file with the list of the files from a folder

Use the > and the folder name or full absolute path to write the list of the files directly into a result text file. Indeed, use the “>” superior symbol to redirect the output to a specific text fil instead of displaying it to the screen. Simply add this redirection symbol at the end of the command.

dir C:\Folder\SubFolder > C:\Folder\list_of_files.txt
Create a text list of files in a folder with cmd and the redirect symbol
Create a text list of files in a folder with cmd and the redirect symbol

4. Display only file names without metadata with CMD

The /b option allows us to only get the files names and extensions in the result output file.

dir C:\Folder\SubFolder \b > C:\Folder\list_of_files.txt
Windows dir command to redirect the list of files and create an output file with only the file names and no details.
Windows dir command to redirect the list of files and create an output file with only the file names

5. Display the files and exclude folders from the list

Another version of the script to make sure to display only the files and exclude the folders:

dir C:\Folder\SubFolder /a /-d /b

The dir /a option allows to specify the elements to display. And also the ones to exclude. The /-d option indicates not to display the folders. For different options of the dir command with no redirection used but simple displays in the command prompt screen, check different ways to list files in folder with cmd.

To sum-up, the redirect option can be super useful and effective to directly create a text list of files in a folder with cmd instead of copying one by one or typing it. For example, after copying recursively multiples files with the same name in different folders, to list them to find any duplicate.