Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Windows DIR Command: How to List Files and Directories

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Windows dir command is a built-in utility used to list the files and subdirectories contained within a specific directory. To use it, simply open the Command Prompt and type dir followed by any desired modifiers or path names. This command allows you to verify the existence of files, check file sizes, view timestamps, and navigate the file system without using a graphical user interface.

What You'll Need

  • A computer running a version of Microsoft Windows.
  • Access to the Command Prompt (cmd.exe) or Windows PowerShell.
  • Basic knowledge of how to navigate folders on your hard drive.

Step-by-Step

  1. Open the Command Prompt: Press the Windows key on your keyboard, type cmd into the search bar, and press Enter. This will open a black window where you can enter text commands.
  2. Identify Your Current Location: When the Command Prompt opens, you will see a directory path (e.g., C:\Users\YourName>). This is your current working directory. Any command you run without specifying a path will happen inside this folder.
  3. Run a Basic Directory Listing: Type dir and press Enter. The system will display a list of every file and folder in your current location. You will see the date and time the file was last modified, whether the item is a directory (marked as <DIR>), the file size in bytes, and the filename.
  4. List Files in a Different Folder: If you want to see the contents of a folder without navigating into it, type dir followed by the path. For example, dir C:\Windows will list the contents of the Windows system folder. If the folder name contains spaces, you must wrap the path in double quotes: dir "C:\Program Files".
  5. Filter Results Using Wildcards: To find specific types of files, use the asterisk (*) wildcard. For example, to list only text files, type dir *.txt. To list every file that starts with the word "report", type dir report*.
  6. Sort the Output: You can organize the list using the /O switch. Type dir /O:N to sort by name (alphabetical), dir /O:S to sort by size (smallest first), or dir /O:D to sort by date (oldest first). To reverse these orders, add a minus sign, such as dir /O:-S for largest files first.
  7. Display Hidden Files: By default, Windows hides system and protected files. To see these, use the /A attribute switch. Type dir /A to show all files, including hidden and system files. To show only hidden files, type dir /AH.
  8. Enable Pagination for Long Lists: If a folder contains hundreds of files, the list will scroll past your screen quickly. To view the results one page at a time, use the pause switch: dir /P. Press any key to scroll to the next page.
  9. List Files in Subdirectories: To see every file in the current folder and every file in every folder beneath it, use the recursive switch: dir /S. This is particularly useful for searching for a lost file across an entire drive.
  10. Create a Bare Format List: If you only need the filenames without the size, date, or summary information, use the bare format switch: dir /B. This is often used when piping the output into a text file for documentation.

Common Mistakes

One of the most frequent errors is forgetting to use quotation marks when dealing with folder paths that contain spaces. For instance, typing dir C:\Users\John Doe\Documents will result in an error because the Command Prompt interprets the space between "John" and "Doe" as the end of the command and the start of a new argument. Always use dir "C:\Users\John Doe\Documents" to ensure the path is read as a single string.

Another common mistake is confusing the dir command with the cd (change directory) command. Users often type dir C:\Windows and expect the prompt to move into that folder. The dir command only looks at the contents; it does not change your current working location. To move into that folder, you must first use cd C:\Windows and then run dir.

Some users mistakenly use forward slashes (/) for file paths, which is common in Linux or macOS. Windows uses backslashes (\) for directory paths. While some modern versions of the Command Prompt are more forgiving, using forward slashes in complex dir strings can lead to "The system cannot find the path specified" errors.

Finally, beginners often forget that the dir /S command can be overwhelming. Running dir /S from the root of the C: drive will list every single file on the entire operating system, which can take several minutes to complete and flood the screen with text. It is always better to navigate to a specific subfolder before running a recursive search.

Tips

To save the output of a dir command to a text file instead of displaying it on the screen, use the redirection operator (>). For example, dir /B > filelist.txt will create a text file containing a clean list of all filenames in the current directory. This is an excellent way to archive a list of your files for backup logs.

You can combine multiple switches to create powerful custom views. For instance, dir /S /B /AH will recursively search all subdirectories for hidden files and display only their full paths in a bare format. This is a highly efficient way to locate hidden configuration files or system logs across a drive.

If you are unsure of the available options for the dir command, you can access the built-in help manual at any time. Type dir /? and press Enter. This will display a comprehensive list of every available switch, attribute, and sorting option supported by your current version of Windows.

To speed up your workflow, use the Tab key for auto-completion. When typing a path, such as dir C:\Users\Jo, pressing Tab will automatically complete the folder name to C:\Users\John, reducing the chance of typos.

Troubleshooting

If you receive the error "File Not Found," double-check your spelling and the path you provided. Ensure that you are using backslashes and that you have included quotes if there are spaces in the folder names. If you are searching for a specific file using wildcards (e.g., dir *.pdf) and it returns "File Not Found," it means there are no files with that extension in the current directory. Try running dir /S *.pdf to search all subfolders as well.

If you see the error "Access is Denied," it means the folder you are trying to list is protected by Windows system permissions. This often happens when trying to access the System Volume Information folder or certain root-level system directories. To resolve this, you must run the Command Prompt as an Administrator. Right-click the Command Prompt icon in the Start menu and select "Run as administrator."

If the command prompt seems to "freeze" when running dir /S, it is likely not frozen but is simply processing a massive number of files. If you need to stop the process before it finishes, press Ctrl + C on your keyboard to terminate the command and return to the prompt.

If the output is scrolling too fast to read, remember to use the /P switch. If you have already run the command and it has finished, you can use the scroll bar on the right side of the window, but note that the Command Prompt has a limited buffer size. If the list was extremely long, the beginning of the list may have been deleted from the memory buffer.

Frequently Asked Questions

Can I use the dir command in PowerShell?

Yes. In PowerShell, dir is actually an alias for the Get-ChildItem cmdlet. While it behaves similarly to the Command Prompt version, some advanced switches may differ. For full PowerShell functionality, Get-ChildItem is the native command.

How do I list only directories and exclude files?

You can use the attribute switch /AD. Typing dir /AD will filter the results to show only folders (directories) and hide all individual files.

Is there a way to list files by their extension?

Yes, by using the wildcard symbol. For example, dir *.jpg will list every JPEG image in the folder, while dir *.exe will list all executable files.

How do I see the total size of all files in a folder?

The standard dir command provides a summary at the bottom of the list. After the list of files, it displays the total number of files and the total number of bytes used by those files combined.

Can the dir command find files on a network drive?

Yes, as long as the network drive is mapped to a letter (like Z:). You can run dir Z: to list the contents of that network location. If it is a UNC path, you may need to use pushd \\Server\Folder first to map it temporarily.

Does the dir command delete any files?

No. The dir command is a read-only operation. It only displays information about the file system and cannot modify, move, or delete any data.