Whenever you want to search and make a list of all files on a specific folder, you used the windows explorer interface to do that. But today in this article we will show other easy ways to that. We will list files using the cmd tool. Command-line provides a simple way to list all the files of a certain type– for example, all your PDF files using the “dir” command. This command will be old news to many but it remains one of the most useful for average PC users. At the end of the post, you will have all switches in order t play with them based on your needs,
How to List all the files in a folder using CMD
- Searching on windows the “cmd” name an open as administrator
- Navigate to your path where you need to list the file by type cd and the path:
- Click Enter
- Execute the following command
Enter “dir” to list the files and folders contained in the folder.
How to List all the files in a folder and subfolder using CMD
If you want to list the files in all the subfolders as well as the main folder, enter:
The lists can be quite long and we will create a file containing the list in order to be very easy. You can rename multiple files at once using CMD.
How to list specific file using wildcards
The dir command can also be used to search for specific files and directories by using wildcards. For example, to list files or directories that begin with the letter “B” you could type:
To list only the items starting with the B letter.
How to Display Based on File Attributes
You can add “/A” followed by a letter code after the DIR command to display files with a specific attribute. These letter codes include:
- D: Displays all directories in the current path
- R: Displays read-only files
- H: Displays hidden files
- A: Files that are ready for archiving
- S: System files
- I: Not content indexed files
- L: Reparse points
How to create a text file listing of the files
- Open the command line in the folder of interest. Example:
- Execute the following command:
dir > listoffiles.txt
- The command will create a list with 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 the following command
dir /s >listmyfiles.txt
The file “listoffiles.txt” will be created automatically in the working folder.
Give the full pathname to create the file elsewhere. For example:
Could be used to place the list on an external drive D:
How to create a text file listing only certain types of files
You may want a list of certain types of files such as pdf files. The dir command allows the use of the wildcard symbol *, which adds very useful functionality. Here are some examples.
How to create a list of all the PDF files in a folder and its subfolders:
The command is:
dir /s *.pdf >listpdf.txt
The command will create a list of PDF 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 would be:
dir /s/b *.pdf >listpdf.txt
How to display only files without folder names
Adding /a-d to the command removes the names of the directories, so all we have are the file names.
dir /a-d /b >..\listmyfiles.txt
How to Display Results in Columns
You can use the /D switch to display results in two columns instead of one. When you display results this way, the Command Prompt does not show extra file information (file size and so on)—just the names of the files and directories.
How to Display Results in Lowercase
The /L switch displays all names of files and folders as lowercase.
Display Results Sorted by Time
Using the /T switch along with a letter code lets you sort results by the different time stamps associated with files and folders. These letter codes include:
- A:The time the item was last accessed.
- C:The time the item was created.
- W:The time the item was last written to. This is the default option used.
So, for example, to sort results by the time items were created, you could use the following command:
All Switches Key
Below are all switches where you can use to create a complex list:
Syntax DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]
- [pathname] The drive, folder, and/or files to display, this can include wildcards:
- * – Match any characters
- ? – Match any ONE character
- /P Pause after each screen of data.
- /W Wide List format, sorted horizontally.
- /D Wide List format, sorted by vertical column.
- [file_attributes] /A[:]attribute
- /A:D Folder /A:-D NOT Folder
- /A:R Read-only /A:-R NOT Read-only
- /A:H Hidden /A:-H NOT Hidden
- /A:A Archive /A:-A NOT Archive
- /A:S System file /A:-S NOT System file
- /A:I Not content indexed Files /A:-I NOT content indexed
- /A:L Reparse Point /A:-L NOT Reparse Point (symbolic link)
- /A:X No scrub file /A:-X Scrub file (Windows 8+)
- /A:V Integrity /A:-V NOT Integrity (Windows 8+)
- /A Show all files
Several attributes can be combined e.g. /A:HD-R
- [sorted] Sorted by /O[:]sortorder
- /O:N Name /O:-N Name
- /O:S file Size /O:-S file Size
- /O:E file Extension /O:-E file Extension
- /O:D Date & time /O:-D Date & time
- /O:G Group folders first /O:-G Group folders last
several attributes can be combined e.g. /O:GEN
- [time] /T: the time field to display & use for sorting
- /T:C Creation
- /T:A Last Access
- /T:W Last Written (default)
- /S include all subfolders.
- /R Display alternate data streams.
- /B Bare format (no heading, file sizes, or summary).
- /L use Lowercase.
- /Q Display the owner of the file.
- /N long list format where filenames are on the far right.
- /X As for
- /N but with the short filenames included.
- /C Include thousand separator in file sizes.
- /-C Don’t include a thousand separators in file sizes.
- /4 Display four-digit years. In most recent builds of Windows, this switch has no effect.
The number of digits shown is determined by the ShortDate format set in the Control Panel.
This is all about the methods of how to list files in cmd. Not only but also playing with to get a certain result like export them on a text file or listing only certain types of files.