Skip to main content

How to List Files in a Directory in CMD

• 1 min read
cmd command-prompt directory dir files windows

You can use the following syntax in Command Prompt (CMD) to list only the files in a directory:

dir /A:-D

This example will list all files in the current directory, excluding subdirectories.

Note: The /A:-D flag specifies shows only files in a directory, excluding any directories.

The following example shows how to use this syntax in practice.

Example: List Files in a Directory in CMD

Suppose that we want to get only the files in the following directory:

C:\Users\admin\Documents\cmd_script

We can type the following command to list the files in the directory:

dir C:\Users\admin\Documents\cmd_script /A:-D
```powershell
The following screenshot shows how to use this syntax in practice:

!List files in directory

We can see that only the files in **C:\Users\admin\Documents\cmd_script** are listed, excluding any subdirectories.

## Conclusion

We can use the **dir** command followed by the path and the `/A:-D` flag to list only the files in any directory on the system.

You can find more topics about Active Directory tools and PowerShell basics on the [ActiveDirectoryTools](https://activedirectorytools.net/) home page.