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.

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: 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.

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 List files and folders in the current directory using Command Prompt To list all files and folders in the current directory and subdirectories: DIR /S List recursive files and folders in Command Prompt To list only folders in the current directory: DIR /AD List only folders in the current directory in Command Prompt To list only folders in the current directory and subdirectories: DIR /AD /S List only folders in the current directory and subdirectories in Command Prompt To list all files in the current directory and exclude all folders: DIR /A-D List all files and exclude folders in the current directory in Command Prompt To list all hidden system files in the current directory: DIR /ASH List all hidden system files in current directory in Command Prompt To list all system files and exclude read-only files in the current directory and subdirectories: DIR /A:S-A /S List all system files and exclude read-only files in the current directory and subdirectories using Command Prompt 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 List all files with a specific file type using Command Prompt To list multiple file types in the current directory and subdirectories: DIR *.txt *.doc *.docx /S List multiple file types in the current directory and subdirectories from Command Prompt

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. Note: You can change the file type extension to list the files you are looking for.

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.