ThisCalculator

Everyday

List Files and Folders in Command Prompt

Updated · Standard formula, shown below

List Files and Folders in Command Prompt

To list files and folders in Windows Command Prompt, type dir and press Enter. It shows the contents of the current directory; add a folder path or options such as /a and /s to change what appears.

What the DIR command shows

dir is the standard Command Prompt command for displaying directory contents. A directory is another name for a folder. In a typical result, each entry includes a date and time, a marker such as <DIR> for a folder, a file size for files, and the name.

At the bottom, Command Prompt usually reports the number of files and directories shown, along with the combined size of the files. Hidden or system entries are not necessarily included in the basic listing. The command displays information; it does not open, move, or delete the listed items.

Run DIR in the current folder

  1. Open Command Prompt. For example, search for “Command Prompt” from the Start menu.
  2. Check the prompt before the cursor. It often ends with a path such as C:\Users\Alex>, showing the current directory.
  3. Type dir and press Enter.

If you want to list a different folder, provide its path after the command. For example:

  • dir C:\Users\Alex\Documents lists that Documents folder without changing the current directory.
  • dir .. lists the parent folder of the current directory.
  • dir C:\ lists the root of the C: drive.

Paths containing spaces should be enclosed in double quotes, for example dir "C:\Program Files". This tells Command Prompt to treat the whole path as one argument.

Useful DIR options

Options, also called switches, begin with a forward slash. You can combine several options in one command.

  • dir /a includes entries with attributes that a plain listing may omit, including hidden items. To request a particular attribute, use forms such as dir /ah for hidden entries or dir /as for system entries. Access restrictions can still affect what is displayed.
  • dir /s lists files and folders in the specified directory and its subdirectories. For example, dir C:\Work /s searches through the Work folder tree and can produce a long output.
  • dir /b uses a bare format: it prints names without the usual dates, sizes, and summary. It is useful when you want a compact list.
  • dir /o:n sorts by name. Other sort choices include /o:d for date and time and /o:s for size. Add a minus sign to reverse a sort, as in dir /o:-n.
  • dir /p pauses after each screen of output. Press a key to continue. Alternatively, dir /w uses a wide layout with names arranged across the screen.

For example, dir /a /o:n /p includes entries with attributes, sorts by name, and pauses between screens. To see the options supported by your Windows installation, run dir /?.

List only files or only folders

dir normally shows both files and folders. To show folders only, use dir /ad. To show files only, use dir /a-d; the minus sign excludes directory entries. You can add a path to either command, such as dir C:\Work /ad.

To filter by a filename or extension, add a pattern. For instance, dir *.txt lists matching text files in the current directory, while dir C:\Work\*.docx checks for matching files in that folder. A wildcard character * represents any number of characters, and ? represents a single character. A pattern does not make dir search all subfolders; add /s when you need a recursive search.

Save or search a listing

To save the output in a text file, redirect it with the greater-than symbol. For example:

dir /b C:\Work > files.txt

This writes the listing to files.txt in the current directory, replacing that file if it already exists. Use >> instead of > to append output to an existing file. Choose a destination outside the folder you are listing when practical, so the output file does not become part of the list you are collecting.

For a long display, you can send output through more: dir /s | more. The vertical bar passes the command’s output to the next command, which displays it one screen at a time. If you need to find a word in a listing, a command such as dir /s | findstr /i "report" filters the text for a case-insensitive match. This searches the displayed output; it is not a full-content search inside files.

DIR compared with other ways to browse

File Explorer provides a graphical view, with icons and navigation controls. Command Prompt’s dir is useful when you are already working in a terminal, need a quick text listing, or want to redirect results to a file or combine them with other commands.

PowerShell offers its own file-listing command, Get-ChildItem, commonly shortened to gci or ls there. These names are not the Command Prompt command: in Command Prompt, use dir. Also, Command Prompt’s dir is a built-in command, not a separate program that must be installed.

Common problems and limitations

  • The wrong folder appears: Check the path shown in the prompt, or give dir the full path you want to inspect.
  • A path with spaces fails: Put the complete path in double quotes.
  • Some entries are missing: Try dir /a to include hidden and other attribute-marked entries. You may still be unable to view protected locations without sufficient permissions.
  • The output is too long: Narrow the path or filename pattern, or use dir /p or dir | more to read it page by page.
  • A command seems to do nothing: Confirm the folder exists and check spelling, drive letter, and quotation marks. A folder with no matching entries may produce no file names.

A listing reflects what the command can access at that moment. It does not guarantee that a file can be opened, and it does not show every detail available in File Explorer’s Properties window. Use care with redirection: > replaces the destination file rather than merely displaying information.

Frequently Asked Questions

What command lists files and folders?
Type dir in Command Prompt and press Enter. Add a path to list a different folder.

How do I list all files, including hidden ones?
Use dir /a. This asks for entries with all attributes, including hidden entries, subject to permissions.

How do I list files in subfolders?
Use dir /s, optionally followed by a folder path or filename pattern, such as dir C:\Work\*.txt /s.

How do I show only folder names?
Run dir /ad. For a compact names-only listing, combine it with /b: dir /ad /b.

How do I save the list to a text file?
Use output redirection, for example dir /b > listing.txt. The file is created in the current directory unless you specify another destination.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.