How-To Guide

    How to List Files in CMD on Windows

    The dir switches you actually need, copy-paste examples for subfolders, files or folders only, hidden files, sorting and counting, and how to save the list to a text file.

    Published November 2, 2026Updated November 2, 20266 min read
    Mehrab Ali

    Author

    Mehrab Ali

    Founder & Executive Lead, ARCED International

    Founder of ARCED Foundation, ARCED International, and Solutions of Things Lab (SoTLab). Built FolderManifest to help teams protect file integrity and stay audit-ready.

    Quick Answer

    To list files in CMD on Windows, open Command Prompt in the folder and run dir. Use dir /b /a-d for file names only, dir /b /s /a-d to include every subfolder with full paths, and add > files.txt to save the list. dir is built into Windows 10 and 11; nothing to install.

    Every command below runs in Command Prompt (cmd.exe). In PowerShell, dir is an alias for Get-ChildItem and the slash switches don't work; see our PowerShell Get-ChildItem guide for that shell.

    Open Command Prompt in the Right Folder

    The fastest way: open the folder in File Explorer, click the address bar, type cmd, and press Enter. Command Prompt opens already in that folder. Otherwise, change to it with cd:

    cd /d "D:\Projects\Client A"
    dir

    /d lets cd switch drives at the same time. Quote any path that contains spaces. You can also skip cd and pass the path to dir directly: dir "D:\Projects\Client A".

    dir Switches You Will Use

    SwitchWhat it does
    /bBare format: names only, no header, dates, or sizes. With /s, prints full paths.
    /sIncludes every subfolder, all levels down.
    /a-dFiles only (everything without the directory attribute), hidden files included.
    /adFolders only.
    /a / /ahAll items including hidden and system / hidden items only.
    /oSort order: /o:n name, /o:s size, /o:d date, /o:e extension. Add - to reverse, e.g. /o:-s.
    /t:c / /t:wShow (and sort by) created or last-written time.
    /qShows the owner of each file.
    /p / /wPause after each screen / wide multi-column view.

    Switches can be combined in any order: dir /s /b /a-d and dir /a-d /b /s do the same thing. Run dir /? for the full list.

    Common Examples

    :: Files and folders here, with dates and sizes
    dir
    
    :: File names only, no folders
    dir /b /a-d
    
    :: Every file in every subfolder, one full path per line
    dir /b /s /a-d
    
    :: Folders only, top level / all levels
    dir /b /ad
    dir /b /s /ad
    
    :: Include hidden and system files
    dir /a
    
    :: Count files in this folder and all subfolders
    dir /b /s /a-d | find /c /v ""

    Lines starting with :: are comments; you can paste the whole block into a .bat file. For a total size, run dir /s /a-d without /b: the last lines under Total Files Listed show the file count and bytes for the whole tree.

    Filter, Sort, and Search with dir

    :: Only PDFs, all subfolders
    dir /b /s *.pdf
    
    :: Several types at once
    dir /b /s *.jpg *.png *.heic
    
    :: Find a file by part of its name anywhere on D:
    dir /b /s "D:\*invoice*"
    
    :: Largest files first
    dir /a-d /o:-s
    
    :: Newest first
    dir /a-d /o:-d
    
    :: Files last modified more than 30 days ago (forfiles, built in)
    forfiles /s /m *.* /d -30 /c "cmd /c echo @path"

    Wildcards match names only: * is any run of characters and ? is one character. To filter on text inside the listing, pipe it to findstr, for example dir /b /s | findstr /i "\\archive\\" to keep only paths under any folder named archive. Need the folder hierarchy drawn as a diagram instead of a flat list? Use the tree command.

    Save the File List to a Text File or the Clipboard

    :: Save to the Desktop (overwrite)
    dir /b /s /a-d > "%USERPROFILE%\Desktop\files.txt"
    
    :: Append to an existing list
    dir /b /s /a-d >> "%USERPROFILE%\Desktop\files.txt"
    
    :: Copy the names to the clipboard
    dir /b /a-d | clip
    
    :: Keep non-English file names intact (UTF-16 output)
    cmd /u /c dir /b /s /a-d > "%USERPROFILE%\Desktop\files.txt"
    
    :: Size in bytes + full path for every file (type at the prompt;
    :: in a .bat file write %%F instead of %F)
    for /r %F in (*) do @echo %~zF	%F

    If you save the list inside the folder you are listing, the text file shows up in its own output. Writing to the Desktop avoids that. For a list with sizes and dates that opens cleanly in Excel, PowerShell's Export-Csv is easier than parsing dir text. To put the list on paper, see how to print a list of files in a folder.

    Access denied on big scans

    Running dir /s on C:\ or C:\Users prints Access is denied for protected folders and keeps going. Add 2>nul to the end of the command to hide those messages; the listing itself is not affected.

    When a File List Isn't Enough

    A dir list tells you which file names exist. It can't tell you whether a copy matches the original: a backup can have every name and size right while one file is corrupted or an older version. Comparing two text lists in Notepad also falls apart past a few hundred lines.

    FolderManifest builds a folder manifest: every file with its path, size, dates, and a SHA-256 hash, exported as HTML, CSV, or Markdown. Check a backup or migrated copy against it and it reports exactly which files were added, removed, or changed. It runs locally on Windows 10/11, macOS, and Linux.

    You may not need it

    For a one-off list or a quick batch file, dir is the right tool. A manifest is worth it when you have to prove a copy is complete and unchanged, or check the same folder again next month.

    Checking two folders right now? Follow our guide to comparing two folders on Windows.

    Frequently Asked Questions

    How do I list all files in a folder in CMD?

    Open Command Prompt in the folder (type cmd in the File Explorer address bar and press Enter) and run dir. Use dir /b for names only, dir /a-d for files without folders, and dir /s to include every subfolder.

    How do I list files in all subfolders with full paths?

    Run dir /b /s /a-d. /s recurses into every subfolder, /b prints one full path per line, and /a-d drops the folder entries so only files remain.

    How do I list only folders in CMD, not files?

    Run dir /b /ad for the folders directly inside the current folder, or dir /b /s /ad to list every folder and subfolder with its full path.

    How do I save the dir output to a text file?

    Redirect it with >: dir /b /s /a-d > "%USERPROFILE%\Desktop\files.txt". Writing to the Desktop keeps the text file out of its own listing. Use >> to append instead of overwrite, or | clip to copy the list to the clipboard.

    Does dir show hidden files?

    Plain dir skips hidden and system files. Add /a to show everything, /ah for hidden items only, or /a-d for all files (hidden included) without folders.

    How do I count the files in a folder with CMD?

    Run dir /b /s /a-d | find /c /v "". It prints the number of files in the folder and all its subfolders. Drop /s to count only the top level.

    Go From a File List to Proof

    Record every file with its SHA-256 hash, then check any later copy against it. Windows, Mac, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.

    Continue Learning