email Feedback About This Page
howtogeek.com: How to Use the DIR Command in Windows by Brady Gavin, 2022-Jul-25
The dir command is a powerful Windows Command Prompt function that lists all files and subdirectories contained in a specific directory. It has options that unlock powerful functionality.
To display just the directories in the current path, type:
then hit the Enter key.
The codes can be combined. Example: to show only system files that are also hidden, use the command:
Can add a - (minus) in front of any of those letter codes to specify that the dir command does not show that kind of file. Example: don’t want to see any directories in the results, use command:
dir /a-d dir /ash
📝 Another Tip: Instead of cramming the main switch and the letter code together the way that was done in previous examples, can use a colon, : , to separate the options from its the codes:
This can make it easier to read and understand.
In recent versions of Windows, the dir shows large numbers separated by commas - ie. 25,000 instead of 25000. In older versions, the /c option was used to show commas.If you don’t want to show commas, use this option with the - (minus sign):
Use /d to display results in 2 or more columns instead of one column.
The number of columns shown depends how wide the Command Prompt window is - 2, 3, 5 or ...
When used just the names of the files and directories are shown.
When the result is piped to a text file only 2 columns are shown.The command:
In the past the /n option had been used to display file names to the far right.
📝 Note : When the names are shown on the left they are shown in the 8.3 filename format and all in uppercase characters .To show file names on the left, use /n along with a - (minus):
To sort results by time and date, with older entries appearing first:
Can add - (minus) before any of the above options to reverse the order.To sort files by time and date with newer entries appearing first, use:
When directories have hundreds or thousands of files, use the /p option to have dir pause the results after it displays each screen. A key is pressed to view the next page of files.The command:
The /w option is similar to /d (which shows columns), but instead, it sorts the results in wide format horizontally.The command:
The /x option shows a file’s short name when the long name doesn’t comply with 8.3 naming rules.The command:
The asterisk (*) acts as a wildcard, it means find anything with .mp3 file format at the end while the /s recursively looks through all folders within the current path.If a LOT of files - too many to read before they scroll off the screen, use the /p pause option to allow the list to be read before moving to the next page:
Use > character to send the results of the dir command to another place or service.
A common practice is to send the file list to a text file. The list can be viewed later or import the file into other types of documents.
To do piping, use the command:
dir \*.mp3 /s /b > filename.txt
The /b option in the above command is there to only output the filenames themselves, without any of the other details.
The greater than > symbol reroutes everything normally displayed in the Command Prompt window directly to the file.