How to list files and folders
Overview
dir lists the files and subfolders in the current folder or in a path you provide.
The output includes dates, file sizes, the free space on the drive, and markers such as <DIR> for folders.
- Wildcards match names:
*means any characters and?means one character. - Listing is read-only, so it is a safe way to verify a path before another operation.
- Use quotes around paths that contain spaces.
Commands to try
Type each command at the prompt, then press Enter. Replace sample names and paths with ones that exist on your computer.
Commands are generally not case-sensitive, but preserving the spelling shown here makes scripts easier to read.
dir
dir "C:\Program Files"
dir *.txt
dir /a /o:n /p
dir /s /b "*.pdf"
Useful options and details
Options change how a command behaves. Add spaces exactly as shown, and use the command's built-in help when an option is unfamiliar.
A path containing spaces must be enclosed in double quotes, such as "C:\My Files".
/aincludes hidden and system entries;/a:dshows folders only./o:nsorts by name and/o:-dsorts newest first./ssearches subfolders,/buses bare output, and/ppauses.
Tips and common mistakes
Check the current folder and read the command output before assuming an operation succeeded.
Practice with disposable files first. Commands that delete, overwrite, or stop a process may not offer an Undo button.
- A broad
dir /scan produce a very long list and take time. - If no files match a wildcard, CMD reports File Not Found; it does not mean the folder is missing.
- A hidden item is not necessarily suspicious; Windows uses hidden files normally.
Safe practice
Create a temporary practice folder under your user profile so the examples cannot affect Windows system files.
After each command, inspect the result with dir or another read-only command before continuing.
- List your user profile with
dir "%USERPROFILE%". - Show folders only and then text files only.
- Sort a listing by name.