The list command in Windows CMD (or `dir`) lets you view files and folders in the current directory. To list visible files only, simply open Command Prompt and run dir. To include hidden files, use dir /a or dir *.txt to filter by extension. No extra tools or permissions are needed—just know the basic syntax and how to customize the output.

What You'll Need

  • A Windows system (Windows 7 or newer) with Command Prompt accessible.
  • Administrator privileges are only required if you need to modify system directories or run certain specialized commands (e.g., dir /s for a full directory tree).
  • Access to a file explorer window open in the directory you want to list (optional).

Step-by-Step

  1. Open Command Prompt:
    1. Press Win + R, type cmd, and hit Enter (Windows 10/11).
    2. Alternatively, search for "cmd" in the Start menu and open it.
    If you’re locked out of Command Prompt (e.g., due to UAC restrictions), try running it as Administrator: right-click the shortcut, select "Run as administrator."
  2. Navigate to the folder you want to list (optional):
    1. Use directory navigation commands like cd C:\Documents to change to a specific folder (replace "Documents" with your path).
    2. To return to the root of your drive, use cd or cd .. to go up one level.
  3. Run the basic dir command:
    1. Type dir and press Enter. This lists visible files and folders in the current directory, formatted with dates, sizes, and a simple directory structure.
    2. Example output:
      
              Volume in drive C is OS
              Volume Serial Number is 1234-5678
      
              Directory of C:\Users\YourName\Desktop
      
              01/01/2024    10:00 AM       100KB  Report.txt
              02/01/2024    09:30 AM       512KB  Project.zip
              -------------
              2 File(s)    612KB
               0 Dir(s)  4,656KB free
              
  4. Customize the output with options:
    1. List only filenames (no details): Type dir /b (e.g., dir /b *.docx to list only Word documents).
      
              Report.txt
              Project.docx
              
    2. Include hidden files (e.g., system files): Use dir /a for all hidden files (including system files, which may require UAC elevation).
      
              dir /a
              
      Example output (restricted to your user profile):
      
              Volume in drive C is OS
              Volume Serial Number is 1234-5678
      
              Directory of C:\Users\YourName
      
              .       01/01/2024    10:00 AM           0
              ..      01/01/2024    10:00 AM           0
              .DS_Store 01/01/2024    10:05 AM       100B
              Report.txt 01/01/2024    10:00 AM       100KB
              
    3. Filter by file extension (e.g., only .txt files): Type dir *.txt or dir *.log to list specific file types.
      
              dir *.log
              AppError.log
              Debug.log
              
    4. Show full directory tree (recursive): Use dir /s to list all files in the current folder and subfolders.
      
              dir /s *.csv
              
      C:\Data\Reports\Sales.csv C:\Data\Subfolder\Reports\Sales.csv Warning: This command can generate large output; avoid running it on system drives unless necessary.
    5. Hide system files (optional): Use dir /o-d /w to sort files by date in descending order and display only names:
      
              dir /o-d /w
              Report.txt
              Project.zip
              
  5. Redirect output to a file (for advanced users):
    1. Run dir > output.txt to save the directory listing to a file.
    2. Useful when scripting or copying large directories.

Common Mistakes

  • Forgetting to navigate to the correct folder: Open File Explorer, navigate to the target directory, then run cmd from there. For example, if you want to list files in "C:\Projects", open File Explorer to "C:\Projects" first, then press Win + R, type cmd, and choose "Run as administrator."
  • Running dir /a without admin rights: Hidden system files (e.g., `.exe`, `.tmp`) are protected. Use dir /a > hidden.txt in an elevated Command Prompt to save output to a file.
  • Using dir /s on system drives: Running this on drives like C:\ can crash your system if it accesses critical files. Always test in a non-system drive first.
  • Typo in the command (e.g., dire instead of dir): Command Prompt treats errors like typos as a normal exit, but you won’t see the listing. Always check for typos before pressing Enter.

Tips

  • Shortcut keys for Command Prompt:
    • Ctrl + C – Stop the current command.
    • Ctrl + V – Paste text (supports clipboard contents).
    • Ctrl + A + Ctrl + X – Cut selected text.
    • Alt + ↑ – Duplicate the last command.
  • Use wildcards (*) to filter dynamically: Run dir *.tmp to list all temporary files in the current directory.
  • Enable verbose mode for long filenames: Type dir /w to display filenames without extra padding, which helps with files over 255 characters (common in modern systems).
  • Check the current working directory: Run echo %cd% to confirm you’re in the right folder before listing files. Example output:
    
        C:\Users\YourName\Desktop
        

Troubleshooting

  1. Command Prompt doesn’t open:
    1. Restart your PC and try again.
    2. Check if Windows features are enabled: Press Win + R, type optionalfeatures, and enable "Command Prompt" under "Desktop and Networking."
    3. If the issue persists, your system may be missing critical components; reinstall Windows or contact support.
  2. Output appears blank or corrupted:
    1. Ensure you’re in the correct directory (use dir first to verify).
    2. For hidden files, run Command Prompt as Administrator and try again.
    3. If using dir /s, try a smaller directory first (e.g., dir /s *.log instead of dir /s).
  3. Command Prompt says "Access Denied":
    1. If listing system files (e.g., dir /a), you need elevated privileges. Run Command Prompt as Administrator (right-click > "Run as administrator").
    2. For restricted folders (e.g., C:\Windows), avoid dir /s unless necessary. Use dir C:\Windows instead (it won’t recurse but will list visible files).
  4. Command Prompt freezes or crashes:
    1. Close and reopen Command Prompt.
    2. Update Windows (Settings > Windows Update) to ensure compatibility.
    3. If problems persist, reset Command Prompt via Add/Remove Programs (Settings > Apps > Apps & Features > Command Prompt > Modify > Repair).

Frequently Asked Questions

What is the simplest way to list files in Command Prompt?

The simplest command is dir. It lists visible files and folders in the current directory, formatted with dates and sizes. No extra steps are needed.

Can I list files in a specific folder without navigating there first?

Yes, but you must either:

  • Open Command Prompt from that folder (e.g., double-click a folder shortcut in the Start menu), or
  • Use the full path in the command, like dir "C:\Users\YourName\Downloads\*.txt".

Why do I get an "Access Denied" error when using dir /a?

Hidden system files (e.g., `.tmp`, `.exe`) are protected by default. To view them:

  1. Run Command Prompt as Administrator (right-click > "Run as administrator").
  2. Alternatively, save the output to a file (e.g., dir /a > hidden.txt) to avoid permission issues.

How do I list all files in a folder and its subfolders?

Use dir /s. For example, dir /s *.jpg lists all JPG files in "C:\Pictures" and its subfolders. Be cautious on system drives!

What does dir /w do?

dir /w displays filenames without extra spacing, which helps with long filenames (common in Windows 10/11). Example:


dir /w
My Very Long Filename That Exceeds 255 Characters.docx
ShortName.txt

Is there a way to sort files by date in Command Prompt?

Yes, use dir /o-d to sort by date (newest first) or dir /o-s to sort by size (largest first). Example:


dir /o-d /w
Report20240101.txt
Project.docx