Key Points
- Use the “DIR” command to list files and folders in the current directory, or “DIR /S” to list files and folders recursively, in subdirectories as well.
- To search for specific file types use the asterisk followed by the file extension type, in this syntax: DIR *.jpg
- Use attribute switches to filter the type of files and folders to list.
It can be tricky to keep tabs on all files and folders on a Windows computer, especially if there are too many. There can be many folders and subfolders inside a partition, and many different types of file extensions. It can be difficult to view all the files and folders, or even search for specific ones using File Explorer.
Using the Command Prompt, you can view and list all sorts of files and folders inside a directory, and even its subdirectories using recursive switches. Not only that, but you can also list all items with a specific file type, or exclude them. Moreover, you can also view hidden items as well directly from the Command Prompt.
In this article, we give you a bunch of different examples to list files and folders inside the Command Prompt using the DIR cmdlet.
Table of Contents
Command to List Files and Folders in Command Prompt
The DIR command is used to list files and folders inside a directory in Command Prompt. This command can be used with a number of switches and attributes to filter the items to display, their order or displaying, to include and exclude, and so on.
However, the only switches we will be interested in are /a and /s.
Using the DIR
command alone will display all the files and folders inside that particular directory. It will not show any hidden items, and it will now show any items inside the subdirectories. However, if you use DIR /a
, it will show the hidden items as well.
To perform a recursive search, we must use the /s
switch.
The table below summarises the commands to use to list files and folders and these switches:
Command | Description |
DIR | Display items inside the current directory |
DIR /a | Display all items inside the current directory, including hidden ones. |
DIR /s | List items inside the current directory as well as all subdirectories |
With that known, there is a list of attributes that you can use with the DIR /a
cmdlet to filter the type of information you want to list. Here is a list of the attributes you can use with /a
.
Attribute Alphabet | Description | Syntax Example |
d | Shows directories only | DIR /ad |
h | Show hidden items only | DIR /ah |
s | Show system files only | DIR /as |
l | Show reparse points only | DIR /al |
r | Show read-only files | DIR /ar |
a | Show files that can be archived | DIR /aa |
i | Show files whose content is not indexed | DIR /ai |
– (hyphen) | Used before an attribute to exclude it from the list | DIR /a-s (hide system files) |
: (colon) | To combine multiple attributes | DIR /a:h-s (Show hidden items but hide system files) |
Example Commands to List Files and Folders in Command Prompt
Let us now continue to see more extensive examples with images to better understand how you can list files and folders using the DIR
cmdlet.
-
To list all files and folders in the current directory:
DIR
-
To list all files and folders in the current directory and subdirectories:
DIR /S
-
To list only folders in the current directory:
DIR /AD
-
To list only folders in the current directory and subdirectories:
DIR /AD /S
-
To list all files in the current directory and exclude all folders:
DIR /A-D
-
To list all hidden system files in the current directory:
DIR /ASH
-
To list all system files and exclude read-only files in the current directory and subdirectories:
DIR /A:S-A /S
-
To list all specific file type files in the current directory and subdirectories:
Note: You can change the file type extension to list the files you are looking for.
DIR *.txt
-
To list multiple file types in the current directory and subdirectories:
DIR *.txt *.doc *.docx /S
There can be many different examples and syntaxes to list files and folders inside the Command Prompt. However, we hope that the examples above are sufficient so that you can combine and modify them as per your requirements.
Closing Words
The Windows command line offers much more control over the fetched data than its GUI. Using the Command Prompt, you can list different files and folders inside the current directory as well as its subdirectories. You can also filter out the type of files and folders to include, or exclude from the list.