If you have ever wanted to make a list of all the files contained in a particular folder, you will have discovered that the Windows Explorer interface provides no easy way to do this. It is very straightforward, however, when using the command line. Furthermore, the command line provides a simple way to list all the files of a certain type- for example, all your MP3 files. The method uses the directory or "dir" command. This command will be old news to many but it remains one of the most useful for average PC users.
List on the screen all the files in a given folder and its subfolders
- Open the command line at the folder of interest (see previous tip).
- Enter “dir” (without quotes) to list the files and folders contained in the folder.
- If you want to list the files in all the subfolders as well as the main folder, enter “dir /s” (without quotes) instead.
The lists can be quite long and the screen is often not where you want the list displayed. Fortunately, creating a file containing the list is very easy.
Create a text file listing of the files
The output can be sent to a text file by using the redirection symbol “>” (no quotes).
- Open the command line at the folder of interest.
- Enter “dir > listmyfolder.txt” (without quotes) to list the files and folders contained in the folder.
- If you want to list the files in all the subfolders as well as the main folder, enter “dir /s >listmyfolder.txt” (without quotes)
The file "listmyfolder.txt" will be created automatically in the working folder. (Of course, you can use any name you choose but it is best to keep the extension .txt.) The list can be kept for reference and printed if desired. The list does not have to be placed in the working folder. Give the full pathname to create the file elsewhere. For example, “dir >F:\listmyfolder.txt” could be used to place the list on an external drive F:
Create a text file listing only certain types of files
Rather than listing all the files in a folder, you may desire a list of certain types such as pictures or music. The dir command allows the use of the wildcard symbol *, which adds very useful functionality. Here are some examples.
List all the MP3 files in a folder and its subfolders
The command becomes:
- dir /s *.mp3 >listmp3.txt
This creates a list of MP3 files only.
List all the JPEG pictures in a folder and its subfolders
The command becomes:
- dir /s *.jpg >listjpg.txt
This creates a list of JPEG files only.
A simpler format
The commands as written will make lists that include information about files such as size and date of creation. A simpler list containing only file names (with full path) can be obtained with the switch "/b". An example command would be:
- dir /s/b *.jpg >listjpg.txt
A fuller explanation of using the command line is at this link.
Get your own favorite tip published! Know a neat tech tip or trick? Then why not have it published here and receive full credit? Click here to tell us your tip.