How To List Files And Folders In Windows Using Command Prompt

How To List Files In Windows Using Command PromptHow To List Files In Windows Using Command Prompt

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.

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:

CommandDescription
DIRDisplay items inside the current directory
DIR /aDisplay all items inside the current directory, including hidden ones.
DIR /sList items inside the current directory as well as all subdirectories
Commands to list files and folders using Command Prompt

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 AlphabetDescriptionSyntax Example
dShows directories onlyDIR /ad
hShow hidden items onlyDIR /ah
sShow system files onlyDIR /as
lShow reparse points onlyDIR /al
rShow read-only filesDIR /ar
aShow files that can be archivedDIR /aa
iShow files whose content is not indexedDIR /ai
– (hyphen)Used before an attribute to exclude it from the listDIR /a-s (hide system files)
: (colon)To combine multiple attributesDIR /a:h-s (Show hidden items but hide system files)
Command Prompt syntaxes to list files and folders using attributes

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
    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
    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
    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
    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 current directory in Command Prompt
    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
    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
    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
    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
    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.

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.

If you liked this post, Share it on:
Subhan Zafar is an established IT professional with interests in Windows and Server infrastructure testing and research, and is currently working with Itechtics as a research consultant. He has studied Electrical Engineering and is also certified by Huawei (HCNA & HCNP Routing and Switching).

Leave the first comment

Get Updates in Your Inbox

Sign up for the regular updates and be the first to know about the latest tech information

Talk to us now

Talk to us straight and get your questions answered right away

Tell Us About Your Project