How to List all Files in a Directory using CMD in Windows
Last Updated :
06 Mar, 2025
Struggling to find or organize files buried in folders on your Windows PC? While File Explorer offers a visual way to browse, the Command Prompt (CMD) provides a faster, more powerful method to list, sort, and manage files, especially when dealing with large directories or automating tasks.
In this quick guide on how to list all files in a directory using CMD in Windows, you will explore how to use simple CMD commands like dir to instantly display every file and subfolder in any directory. We’ll break down the syntax, explain how to filter results (by name, date, or type), and share tricks to export lists for backups.
Prerequisites to Access Directory in Win
- Windows PC (11, 10, 8 or 7)
- Administrator Rights
- Familiar with Command Prompt actions (or knowing how to open it, i.e. Win + R & type CMD)
What Command Can Be Used to List Files
The "dir" command is fundamental in the Windows Command Prompt, which is used to list the contents of a directory. Here's a bit more detail on how it works.
1. Basic Usage
- When you type dir and press Enter in the Command Prompt, it lists all the files and directories in the current directory.
- By default, it displays the file name, size, and modification date and time.
2. Options
- /A: This option displays files with specified attributes. For example, /A: H displays hidden files.
- /B: Uses a bare format with no heading information or summary. It simply lists the names of files and directories.
- /O: Specifies the order in which files are sorted. For instance, /O: N sorts files by name.
- /S: Displays files in the specified directory and all subdirectories.
- /P: Pauses after each screenful of information.
- /W: Uses wide list format, displaying as many as five file names in each row.
3. Example Usage
- dir /A: Lists all files including hidden files in the current directory.
- dir /B: Displays a bare list of files and directories without any additional information.
- dir /O:N: Sorts files by name.
- dir /S: Lists files in the specified directory and all subdirectories.
How to List All Files in a Directory
Now, we will be discussing 4 basic steps to list all files in a directory using the Command Prompt. Let's check them out:
Step 1: Open Command Prompt
- First things first, let's open the Command Prompt. You can do this by searching for "Command Prompt" in the Start menu or by pressing the Win + R keys, typing "cmd" in the "Run" dialog, and hitting Enter.
Open Command PromptStep 2: Navigate to the Directory
- Once you have the Command Prompt open, you need to navigate to the directory whose files you want to list. To do this, use the cd command followed by the path of the directory. For example, if you want to list files in a directory named "Documents" located in your user folder, you would type:
cd Documents
Press Enter after typing the command to change the directory.
Step 3: List Files
- Now that you're in the desired directory, it's time to list all the files it contains. To do this, simply type the "dir" command and press Enter. This command displays a list of files and directories in the current directory.
List FilesStep 4: Additional Options (Optional)
- If you want to customize the way files are listed, you can use various options with the dir command. Here are some common options:
/A: Displays files with specified attributes.
/B: Uses bare format (no heading information or summary).
/O: Specifies the order in which files are sorted.
/S: Displays files in specified directory and all subdirectories.
For example, if you want to list all files including hidden files in bare format, you would type:
dir /A /B
Use Cases for Listing Files in CMD
- IT Audits: Export a list of all
.exe
files in a directory for compliance checks. - Scripting Backups: Automate file logging with a batch script.
- Troubleshooting: Identify missing or corrupted files in large folders.
CMD vs PowerShell: Which One to Use
Task | CMD Command | PowerShell Equivalent |
---|
List files | dir | Get-ChildItem |
Filter by date | dir /od | Get-ChildItem | Sort LastWriteTime |
Export to text file | dir > output.txt | Get-ChildItem > output.txt |
Conclusion
Mastering the dir command in CMD lets you efficiently manage files, automate tasks and troubleshoot Windows system within a few steps. By following the outline steps, you can use the Command Prompt to organize your workspace or troubleshooting, without replying on graphical interfaces. Whether you're an IT expert, a developer (for scripting batch jobs) or a casual user organizing personal documents, the ability to list files in a directory using CMD is a must-know job that everyone should know.
Also Read
Similar Reads
Sed Command in Linux/Unix With Examples
The SED command is one of the most powerful commands used during the process of text processing in Linux/Unix operating systems. The SED command is typically invoked for executing operations such as replace and search, text manipulation, and stream editing.With SED, you can manipulate text files wit
9 min read
How to Find the Wi-Fi Password Using CMD in Windows
Forgotten your Wi-Fi password? Need to connect a new device but canât recall the complex string of characters? You donât have to scramble for that sticky note or reset your router just yet! Hidden within Windows is a powerful, built-in tool that lets you retrieve your Wi-Fi password quickly and secu
8 min read
How to Securely Copy Files in Linux | scp Command
Secure file transfer is a crucial part of Linux systems administration. Whether moving sensitive files between local machines or transferring data between servers, or you need to move backup files to a remote server, fetch logs from a hosted machine, or sync directories across multiple systems, scp
10 min read
How to Download and Install the Google Play Store
The Google Play Store is the heartbeat of your Android experienceâhome to millions of apps, games, and updates that keep your device functional, fun, and secure. But what if your phone or tablet doesnât have it pre-installed?In this step-by-step guide, youâll learn how to safely download and install
6 min read
How to Change Directories in Command Prompt (CMD)
The Command Prompt (CMD) in Windows is a powerful tool for executing commands, managing files, and navigating your system. One of the most common tasks youâll perform in CMD is changing directories, which allows you to move between folders to access and manage files. But have you know how to change
11 min read
Create virtual environment in Python
A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. Using virtual environments is a common practice in Python development as it helps to manage dependencies for different projects, avoiding
3 min read
How to Clear DNS Cache in Chrome using chrome://net-internals/#dns Command
If you're experiencing website loading issues, seeing outdated pages, or encountering network errors in Google Chrome, clearing your DNS cache (also known as host cache) might be the solution. This method is useful if you are facing problems like slow browsing speeds, site access errors, or incorrec
5 min read
'crontab' in Linux with Examples
If you do manually backups , update logs, or restart services on your Linux machine? Imagine that running repetitive tasks overnight so your machine works for you while you rest. Here crontab, the native job scheduler in Linux, which enables users to easily automate commands, scripts, and system tas
9 min read
ls Command in Linux
The ls command is one of the most used commands in the Linux terminal to display the files and directories or path in the terminal. So, using the ls command is a basic skill for navigating the Linux file system, handling files, and managing directories.What is the ls Command in LinuxThe ls command i
10 min read
How to List all Files in a Directory using CMD in Windows
Struggling to find or organize files buried in folders on your Windows PC? While File Explorer offers a visual way to browse, the Command Prompt (CMD) provides a faster, more powerful method to list, sort, and manage files, especially when dealing with large directories or automating tasks. In this
5 min read