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.
Step 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.
Step 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
- CMD | Dir command
- How to Delete a File or Folder Using CMD?
- Search Files Faster on Windows 10 using Command Prompt
To list all files in a directory using the Command Prompt, you can use the `dir` command, which displays a list of files and folders in the current directory.
dir
Understanding CMD and Its Basics
What is CMD?
Command Prompt, commonly referred to as CMD, is a command-line interpreter in Windows operating systems. It provides a direct interface for users to execute commands and perform various administrative and file management tasks without the need for a graphical user interface (GUI). The flexibility and speed of CMD make it a powerful tool for users who want to automate tasks or manage files efficiently.
Why Use CMD to List Files?
Listing files using CMD is advantageous for several reasons:
- Efficiency and Speed: CMD can display a large number of files much faster than navigating through folders using a GUI.
- Batch Processing Capabilities: Users can manage multiple files or directories at once by executing a single command.
- Command Line vs Graphical Interface: For those skilled in using commands, CMD provides a quicker method to access and manipulate files without the overhead of a graphical display.
List All Drives in Cmd: Quick Guide to Drive Management
Getting Started with CMD
Opening CMD
To open Command Prompt, follow these simple steps:
- Press Windows Key + R to open the Run dialog box.
- Type `cmd` and press Enter.
- Alternatively, you can search for “Command Prompt” in the Start menu and click on it.
Once you have CMD open, you’re ready to start listing files and directories.
List Files Cmd Windows: A Simple Guide
Listing Files in CMD
The Basic Command: `dir`
The primary command for listing files in CMD is `dir`. This command will display the files and folders in your current directory.
Syntax:
dir [options] [path]
A simple way to list files in the current directory is to type:
dir
When you run this command, CMD will output a list of all files and directories in the current working directory, along with metadata like file size and modification date.
Listing Files in a Specific Directory
If you want to list all files in cmd from a specific directory, you can specify the path. For instance, if your directory is `C:\YourDirectory`, you would use:
dir C:\YourDirectory
This command will provide a detailed listing of all files and folders located in `C:\YourDirectory`.
Filtering Output with Options
Using Options with `dir`
The `dir` command allows the use of various options to refine your output for better clarity.
Here are some useful options you can use:
- `/p`: This option pauses the output after each screen of information, allowing you to read through it comfortably.
- `/w`: Using this option presents the files in a wide format, making it easier for you to view multiple file names at a glance.
- `/s`: This option lists files in the current directory and all its subdirectories.
For example, if you want the listing to pause after each screen, you would type the following command:
dir /p
Displaying Detailed File Information
Using `/q` and `/t`
For users who need more detailed information, CMD allows for additional options to show file owners and timestamps.
- `/q`: Displays file ownership information.
- `/t:w`: Displays the last written time/date of each file.
An example command that combines these options is:
dir /q /t:w
List Disks in Cmd: A Quick Guide to Disk Management
Advanced File Listing Techniques
Listing Only Specific File Types
Example: Listing .txt Files
You often may need to target specific types of files. Using wildcards can help filter results effectively. For instance, to list only `.txt` files in the current directory, use:
dir *.txt
Using the `*` wildcard allows you to match any characters leading up to `.txt`, giving you a direct list of all text files in the directory.
Creating a Directory Listing File
Redirecting Output to a Text File
Sometimes, you may want to capture your file listing for later reference. This can be accomplished by redirecting the output to a text file using the following syntax:
dir > filelist.txt
This command will create a file called `filelist.txt` in the current directory, containing all the data from the `dir` output.
Using `tree` Command to List Directories
Understanding the `tree` Command
For a more graphical representation of directories, you can use the `tree` command. This command will display all directories and subdirectories in a tree format.
To use the `tree` command, type:
tree C:\YourDirectory
This will visually show the structure of all folders and files under `C:\YourDirectory`, enhancing understanding of the file hierarchy.
List Folders in Cmd: A Quick Guide to Navigation
Practical Tips for CMD Users
Common Mistakes to Avoid
While using CMD, users may encounter common pitfalls, such as:
- Typing errors in command syntax.
- Forgetting to include the necessary options, which can lead you to receive incomplete information.
How to handle error messages: When CMD returns an error, read the message carefully; it usually provides clues about what went wrong.
Keyboard Shortcuts and CMD Tricks
To improve your efficiency while using CMD, familiarize yourself with some keyboard shortcuts:
- Up Arrow: Cycles through previous commands.
- Tab: Auto-completes file and directory names.
How to List the Files in Cmd: A Quick Guide
Conclusion
Understanding how to list all files in cmd is an invaluable skill for efficient file management. With commands like `dir`, options to filter and refine outputs, and advanced techniques for creating streamlined outputs, you can significantly enhance your productivity. Practice these commands to harness the full potential of CMD, and don’t hesitate to explore more functions to optimize your workflow.
Read a File in Cmd: Quick and Easy Steps
Additional Resources
- For further information, you can consult the official Microsoft documentation on CMD, or you may explore CMD-specific forums and online tutorials for community support.
List Services Cmd: Mastering Service Commands Effortlessly
FAQs on Listing Files in CMD
How do I list all files, including hidden ones?
To list all files, including hidden files, you can use the `/a` option:
dir /a
This command will show all files, including those marked as hidden or system files.
Can I list files in a network directory?
Yes, you can list files in a network directory by specifying the network path in the `dir` command:
dir \\NetworkPath\YourDirectory
Make sure you have proper permissions to access the network folder.
What if CMD is not recognizing the command?
If CMD doesn’t recognize a command, check your spelling and ensure you’re using the correct syntax. You may also need to verify that the command is available in your version of Windows or that your environment variables are set correctly.
By mastering these commands and understanding their nuances, you can become highly efficient in managing files directly from the command line. Happy commanding!
Whenever you want to search and make a list of all files on a specific folder, you used the windows explorer interface to do that. But today in this article we will show other easy ways to that. We will list files using the cmd tool. Command-line provides a simple way to list all the files of a certain type– for example, all your PDF files using the “dir” command. This command will be old news to many but it remains one of the most useful for average PC users. At the end of the post, you will have all switches in order t play with them based on your needs,
How to List all the files in a folder using CMD
- Searching on windows the “cmd” name an open as administrator
- Navigate to your path where you need to list the file by type cd and the path:
cd c:\Test\
- Click Enter
- Execute the following command
dir
Enter “dir” to list the files and folders contained in the folder.
How to List all the files in a folder and subfolder using CMD
If you want to list the files in all the subfolders as well as the main folder, enter:
dir /s
The lists can be quite long and we will create a file containing the list in order to be very easy. You can rename multiple files at once using CMD.
How to list specific file using wildcards
The dir command can also be used to search for specific files and directories by using wildcards. For example, to list files or directories that begin with the letter “B” you could type:
dir b*
To list only the items starting with the B letter.
How to Display Based on File Attributes
You can add “/A” followed by a letter code after the DIR command to display files with a specific attribute. These letter codes include:
- D: Displays all directories in the current path
- R: Displays read-only files
- H: Displays hidden files
- A: Files that are ready for archiving
- S: System files
- I: Not content indexed files
- L: Reparse points
How to create a text file listing of the files
- Open the command line in the folder of interest. Example:
cd c:\Test\
- Execute the following command:
dir > listoffiles.txt
- The command will create a list with the files and folders contained in the folder.
- If you want to list the files in all the subfolders as well as the main folder, enter the following command
dir /s >listmyfiles.txt
The file “listoffiles.txt” will be created automatically in the working folder.
Give the full pathname to create the file elsewhere. For example:
dir >D:\listmyfiles.txt
Could be used to place the list on an external drive D:
How to create a text file listing only certain types of files
You may want a list of certain types of files such as pdf files. The dir command allows the use of the wildcard symbol *, which adds very useful functionality. Here are some examples.
How to create a list of all the PDF files in a folder and its subfolders:
The command is:
dir /s *.pdf >listpdf.txt
The command will create a list of PDF files only.
A simpler format:
The commands as written will make lists that include information about files such as size and date of creation. A simpler list containing only file names (with full path) can be obtained with the switch “/b”. An example would be:
dir /s/b *.pdf >listpdf.txt
You can also change extension of multiply files using the command line.
How to display only files without folder names
Adding /a-d to the command removes the names of the directories, so all we have are the file names.
dir /a-d /b >..\listmyfiles.txt
How to Display Results in Columns
You can use the /D switch to display results in two columns instead of one. When you display results this way, the Command Prompt does not show extra file information (file size and so on)—just the names of the files and directories.
dir /D
How to Display Results in Lowercase
The /L switch displays all names of files and folders as lowercase.
dir /L
Display Results Sorted by Time
Using the /T switch along with a letter code lets you sort results by the different time stamps associated with files and folders. These letter codes include:
- A:The time the item was last accessed.
- C:The time the item was created.
- W:The time the item was last written to. This is the default option used.
So, for example, to sort results by the time items were created, you could use the following command:
dir /TC
All Switches Key
Below are all switches where you can use to create a complex list:
Syntax DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]
Key
- [pathname] The drive, folder, and/or files to display, this can include wildcards:
- * – Match any characters
- ? – Match any ONE character
- [display_format]
- /P Pause after each screen of data.
- /W Wide List format, sorted horizontally.
- /D Wide List format, sorted by vertical column.
- [file_attributes] /A[:]attribute
- /A:D Folder /A:-D NOT Folder
- /A:R Read-only /A:-R NOT Read-only
- /A:H Hidden /A:-H NOT Hidden
- /A:A Archive /A:-A NOT Archive
- /A:S System file /A:-S NOT System file
- /A:I Not content indexed Files /A:-I NOT content indexed
- /A:L Reparse Point /A:-L NOT Reparse Point (symbolic link)
- /A:X No scrub file /A:-X Scrub file (Windows 8+)
- /A:V Integrity /A:-V NOT Integrity (Windows 8+)
- /A Show all files
Several attributes can be combined e.g. /A:HD-R
- [sorted] Sorted by /O[:]sortorder
- /O:N Name /O:-N Name
- /O:S file Size /O:-S file Size
- /O:E file Extension /O:-E file Extension
- /O:D Date & time /O:-D Date & time
- /O:G Group folders first /O:-G Group folders last
several attributes can be combined e.g. /O:GEN
- [time] /T: the time field to display & use for sorting
- /T:C Creation
- /T:A Last Access
- /T:W Last Written (default)
- [options]
- /S include all subfolders.
- /R Display alternate data streams.
- /B Bare format (no heading, file sizes, or summary).
- /L use Lowercase.
- /Q Display the owner of the file.
- /N long list format where filenames are on the far right.
- /X As for
- /N but with the short filenames included.
- /C Include thousand separator in file sizes.
- /-C Don’t include a thousand separators in file sizes.
- /4 Display four-digit years. In most recent builds of Windows, this switch has no effect.
The number of digits shown is determined by the ShortDate format set in the Control Panel.
Conclusion:
This is all about the methods of how to list files in cmd. Not only but also playing with to get a certain result like export them on a text file or listing only certain types of files.
The dir
command is used to list files and folders in the Windows command prompt (CMD).
dir
The dir
command without a path will display a list of files and folders in the current working directory.
You can provide a path to see the listing for a different directory:
dir C:\Windows
By default, the dir
command does not show hidden files and folders. To include hidden files, run the dir
command as follows:
dir /a
You can use the /B
switch to show the file names only without heading information or summary.
dir /b C:\Windows
The /s
option lists all files in a specified directory and all subdirectories.
dir /s
List Files Using Patterns
The dir
command supports wildcard character (*
) that you can use to describe a pattern to match.
For example, the following command lists all files that begin with the letter A:
dir a*
Here is another example that lists all files that have a .doc
extension:
dir /b *.doc
Displays files with specified attributes
The /A
switch is used to list files and folders with specified attributes. For example, the letter H
represents the hidden attribute.
dir /a:h
The following table describes each of the values that you can use for Attributes.
D | Folders. |
H | Hidden files and Folders. |
S | System files. |
L | Reparse Points. |
R | Read-only files. |
A | Files ready for archiving. |
I | Not content indexed files. |
O | Offline files. |
— | Prefix meaning not (See examples). |
Examples
List Files and folders in C:\Windows\System32
directory:
dir C:\Windows\System32
Obtain a listing of all files in C:\Windows\System32
that ends with the .txt extension:
dir C:\Windows\System32\*.txt
Search for files with .dll
extension in C:\Windows\System32
and all subdirectories:
dir /s C:\Windows\System32\*.dll
Returns the listing for the parent directory of the current working directory:
dir ..
List all files and folders, including hidden files:
dir /a
Show hidden files only:
dir /a:h
List only folders:
dir /a:d
Don’t list folders:
dir /a:-d
Show only hidden folders:
dir /a:dh
List read only files:
dir /a:r
Sort the result by name:
dir /o:n
This will sort the result set by size:
dir /o:s
Sort the result set by size (largest first):
dir /o:-s
Sort the result by date:
dir /o:d
Includes the name of the owner for each file:
dir /q
Show creation time:
dir /t:c
Show last access time:
dir /t:a
Show the last written time:
dir /t:w
Run the dir /?
command to see a list of all the available command-line options.
-
Home
-
Partition Magic
- CMD List Files: How to List Files in Command Prompt Windows 10/11
By Ariel | Follow |
Last Updated
What command can be used to list files in a directory? How to list files in Command Prompt Windows 10/11? A great many people are confused about these questions. In this post, MiniTool explains the Command Prompt list files topic in detail and introduces an alternative to CMD list files.
CMD (Command Prompt) is a powerful Windows built-in tool that can be used to do many works such as CMD copy files, CMD list drives, CMD WiFi password, and more. However, a lot of users don’t how to list files in Command Prompt. Here’s a true example from the StackOverflow forum:
I tried searching for a command that could list all the files in a directory as well as subfolders using a command prompt command. I have read the help for the «dir» command but couldn’t find what I was looking for. Please help me with what command could get this.
https://stackoverflow.com/questions/15214486/command-to-list-all-files-in-a-folder-as-well-as-sub-folders-in-windows
Although there are already many discussions and posts about the Command Prompt list files, most of them lack clear steps and screenshots, which makes people difficult to understand the “CMD list files” operation. Thus, we want to write a complete guide to explain it. Let’s keep reading.
What Command Can Be Used to List Files
To list directory CMD smoothly, you need to know what command can be used to list files in a directory Windows first. The answer is to use the DIR command. This command can be used to show all files and subfolders in the current directory. In addition, it displays the file name, size, and last modification date of each file like File Explorer.
The DIR command is available in CMD for almost all Windows systems, including Windows 11/10/8/7/Vista/XP. Here are the most commonly used command lines about the CMD list directory/files:
- D: List all directories in the current path
- R: Show read-only files
- H: Show hidden files
- A: Archive files
- S: List system files
- I: Not content indexed files
- L: Reparse points
- -: Add a minus in front of any of the file attribute to let the DIR command not show that kind of file.
How to List Files in Command Prompt Windows 10/11
How to list files in CMD Windows 10/11? The answer depends on what files you want to list. Here we summarize several common examples of the Windows Command Prompt list files.
Step 1. First of all, you need to navigate to the directory in which you want to list files in File Explorer.
Step 2. Click on the address bar and type cmd in the file path and hit Enter, which will open the Command Prompt window.
Tips:
Also, you can locate the directory first in File Explorer, and then press the Win + R keys to open the Run box, type cmd in it, and hit Enter to open the Command Prompt window.
Step 3. In the pop-up window, you can list file CMD according to your needs. For example:
Example 1. CMD List all directories and folders under the current path.
dir
Example 2. CMD List folders of the current directory only.
dir /ad
Example 3. CMD list files only under the directory.
dir /a-d
Example 4. CMD list files and folders under a specific directory (e.g. C:Usersdefaultuser1)
cd C:Usersdefaultuser1
dir
Example 5. CMD list all system files under the directory.
dir /s
Example 6. CMD list all read-only non-achieve files.
dir /a:r-a
Example 7. CMD list all files with the file extension .doc.
Tips:
You can replace the doc with other file extensions such as exe, png, xml, etc.
dir *.doc
Example 8. CMD list all files with the file extension .doc and .jpg.
dir *.doc *.jpg
Of course, there are many other dir commands to list file CMD on Windows 10/11 and we can’t explain all in this post. If you want to know more information about Windows CMD list files, you can search for corresponding commands online on Google.
Better Alternative to Command Prompt List Files
Although you can list files in a directory CMD, many professional commands might be unfamiliar to you. How to list all files/folders under a directory more easily? MiniTool Partition Wizard is a better alternative to Windows Command Prompt list files.
Its Space Analyzer feature can show all files/folders under a specific path in the file name, size, last change, extension, percentage of drive, etc. In addition, it tells you what files are taking up your disk space and helps you free up disk space.
MiniTool Partition Wizard FreeClick to Download100%Clean & Safe
About The Author
Position: Columnist
Ariel has been working as a highly professional computer-relevant technology editor at MiniTool for many years. She has a strong passion for researching all knowledge related to the computer’s disk, partition, and Windows OS. Up till now, she has finished thousands of articles covering a broad range of topics and helped lots of users fix various problems. She focuses on the fields of disk management, OS backup, and PDF editing and provides her readers with insightful and informative content.