Create a text list of files in a folder in cmd

How to create a list of files and insert it into a text file with a simple command in Windows? It pretty easy, you need to add in the command to redirect the output of the dir batch comand.

How to create a list of the files contained in a folder into a text file with a Windows command ?

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

dir /s

Or this variant to display explicitly the content of a folder using explicitly the full path :

dir /s C:\Folder\SubFolder 

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.

To create an output file from the list of files generated by the dir command

Use the > and a folder name or 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
windows dir comand to redirect the list of files into an outpout file

Another interesting option is to display only the file names and not all the metadata columns

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 flies in a folder into an output file with only the file names and no details.

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.