CMD Simulator
File Managementdir

DIR Command – List Files and Directories in Windows

Learn how to use the DIR command to display files and subdirectories in Windows Command Prompt. Complete guide with syntax, parameters, examples, and best practices.

Rojan Acharya·
Share

The DIR command is a Windows Command Prompt utility that displays a list of files and subdirectories in a specified directory, showing file names, sizes, modification dates, and attributes. Use DIR to view directory contents, combine with parameters like /S for recursive listing across subdirectories, /A to filter by attributes, and /O to sort results by name, size, date, or extension.

Whether you're a system administrator auditing file systems, a developer exploring project structures, or a power user managing files from the command line, DIR is the fundamental tool for viewing and analyzing directory contents. IT professionals rely on DIR for file system audits, disk space analysis, and automated inventory scripts across enterprise environments.

This comprehensive guide covers DIR syntax, all parameters and sorting options, practical examples for common file listing scenarios, troubleshooting tips for access issues, related directory navigation commands, and frequently asked questions. By the end, you'll confidently list, filter, and analyze directory contents from the command line for file management, system administration, and troubleshooting tasks.

What Is the DIR Command?

The DIR command is one of the most fundamental Windows Command Prompt commands for file system navigation and analysis. It lists all files and subdirectories in the current or specified directory, displaying detailed information including modification dates, file sizes, directory markers (<DIR>), and attribute indicators.

DIR works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), Windows Terminal, and is available in all Windows versions from MS-DOS through Windows 11, Windows Server 2022, and all enterprise editions. Its syntax and core functionality have remained consistent across decades, ensuring scripts written for DOS still work in modern Windows.

The command provides extensive filtering and sorting options, making it invaluable for file system analysis, disk space audits, and automated file inventory tasks. System administrators use DIR to generate file listings, identify large files, find files by attributes, and export directory structures for documentation or compliance.

Why DIR Matters for System Administration

System administrators use DIR extensively for:

  • Auditing file systems for compliance and security
  • Identifying large files consuming disk space
  • Finding files by modification date for backup verification
  • Generating file inventories for documentation
  • Analyzing directory structures before migrations
  • Troubleshooting file access and permission issues

Developers rely on DIR for:

  • Exploring project directory structures
  • Finding files by extension or naming pattern
  • Checking file sizes and modification dates
  • Verifying build outputs and artifacts
  • Analyzing disk space usage in development environments

Syntax

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

Basic Parameters

ParameterDescription
[drive:][path]Specifies the drive and directory to list
[filename]Specifies a file or group of files to list (wildcards supported)
/ADisplays files with specified attributes
/BUses bare format (no heading, summary, or extra information)
/SLists files in specified directory and all subdirectories recursively
/PPauses after each screenful of information
/WUses wide list format (multiple columns)
/OLists files in sorted order
/TControls which time field is displayed or used for sorting

Attribute Filters (/A)

AttributeDescription
DDirectories (folders)
RRead-only files
HHidden files
SSystem files
AFiles ready for archiving
-Prefix meaning "not" (e.g., -D = files only, not directories)

Sort Orders (/O)

Sort CodeDescription
NBy name (alphabetical)
EBy extension (alphabetical)
SBy size (smallest first)
DBy date/time (oldest first)
GGroup directories first
-Prefix to reverse order (e.g., -S = largest first)

Time Fields (/T)

Time CodeDescription
CCreation time
ALast access time
WLast written time (default)

How to Use DIR Command

Display Current Directory Contents

The simplest use of DIR displays all files and folders in your current location:

DIR

Output shows file names, sizes, dates, and a summary of total files and free space.

List Files in a Specific Directory

Specify a path to view contents of any directory without changing your current location:

DIR C:\Windows
DIR D:\Projects\WebApp

Use absolute paths for clarity and reliability in scripts.

List Files Recursively (/S)

Use /S to display files in the specified directory and all subdirectories:

DIR /S
DIR C:\Projects /S

This searches the entire directory tree, showing files in all nested folders.

Display Files in Bare Format (/B)

The /B parameter shows only file names without dates, sizes, or headers:

DIR /B
DIR /B /S

Ideal for piping to other commands or saving to text files for processing.

Filter by File Attributes (/A)

Display only files with specific attributes:

DIR /A:H
DIR /A:D
DIR /A:-D
DIR /A:RH
  • /A:H shows hidden files
  • /A:D shows only directories
  • /A:-D shows only files (excludes directories)
  • /A:RH shows read-only AND hidden files

Sort Directory Listing (/O)

Sort files by name, extension, size, or date:

DIR /O:N
DIR /O:E
DIR /O:S
DIR /O:-S
DIR /O:D
DIR /O:-D
  • /O:N sorts by name (A-Z)
  • /O:E sorts by extension
  • /O:S sorts by size (smallest first)
  • /O:-S sorts by size (largest first)
  • /O:D sorts by date (oldest first)
  • /O:-D sorts by date (newest first)

Display with Pagination (/P)

Use /P to pause after each screenful for large directories:

DIR /P
DIR C:\Windows\System32 /P

Press any key to continue to the next screen.

Use Wide Format (/W)

Display files in multiple columns for compact viewing:

DIR /W

Shows only filenames in 5 columns, omitting sizes and dates.

List Specific File Types

Use wildcards to filter files by extension or pattern:

DIR *.txt
DIR *.exe
DIR report*.docx
DIR data?.csv
  • *.txt lists all text files
  • *.exe lists all executables
  • report*.docx lists files starting with "report"
  • data?.csv lists files like data1.csv, data2.csv

Combine Multiple Parameters

Chain parameters for powerful filtering and sorting:

DIR /S /B *.log
DIR /A:-D /O:-S
DIR /S /A:H /B
  • /S /B *.log lists all .log files recursively in bare format
  • /A:-D /O:-S lists files only, sorted by size (largest first)
  • /S /A:H /B lists all hidden files recursively in bare format

Export Directory Listing to File

Redirect output to save directory listings:

DIR > filelist.txt
DIR /S /B > all-files.txt
DIR /A:D > directories.txt

Use > to create/overwrite or >> to append to existing files.

Common Use Cases

  1. View all files in current directory – Use DIR to see what files and folders exist in your current location before performing operations.

  2. Find large files – Use DIR /O:-S to sort by size (largest first) and identify files consuming disk space for cleanup or archiving.

  3. List all files recursively – Use DIR /S to see files in all subdirectories, useful for finding files across complex directory structures.

  4. Find hidden files – Use DIR /A:H to display hidden files and folders that don't appear in Windows Explorer with default settings.

  5. Export directory listing – Use DIR /S /B > inventory.txt to save complete file lists for documentation, audits, or compliance.

  6. Search for specific file types – Use DIR *.txt or DIR *.log to list only files matching specific extensions for analysis or processing.

  7. View file details – Use default DIR output to see modification dates, file sizes, and attributes for troubleshooting or verification.

  8. List only directories – Use DIR /A:D to show only folders, useful for understanding directory structure without file clutter.

  9. Find recently modified files – Use DIR /O:-D to sort by date (newest first) and identify recently changed files for backup or review.

  10. Generate file inventories – Use DIR /S /B /A:-D > files.txt to create complete file inventories for backup verification or migration planning.

  11. Analyze disk space usage – Use DIR /S to see total file counts and sizes across directory trees for capacity planning.

  12. Find files by date – Use DIR /T:C /O:D to sort by creation date, or /T:A for last access date, useful for compliance or data retention.

Tips and Best Practices

  1. Use /P for large directories – When listing directories with many files, use /P to pause output after each screen: DIR /P. This prevents information from scrolling past too quickly.

  2. Combine /S with /B for clean lists – Use DIR /S /B for clean recursive file lists without headers or summaries, ideal for piping to other commands or saving to files.

  3. Use wildcards to filter files – Filter by extension (DIR *.exe), prefix (DIR report*), or pattern (DIR data?.txt) to focus on specific files.

  4. Redirect output to save listings – Save directory listings for documentation: DIR /S > inventory.txt. Use >> to append to existing files.

  5. Use /A:-D to exclude directories – Show only files without directory entries: DIR /A:-D. This simplifies output when you only care about files.

  6. Combine /O parameters – Sort by multiple criteria: DIR /O:GN groups directories first, then sorts by name. Use /O:GE to group directories and sort by extension.

  7. Use /B for scripting – Bare format (/B) is ideal for batch scripts and automation, providing clean filenames without extra formatting.

  8. Check file attributes – DIR shows attribute letters before filenames: A (archive), R (read-only), H (hidden), S (system). Use to identify file properties.

  9. Use /T to control time display – Display creation time (/T:C), last access (/T:A), or last write time (/T:W, default) for different analysis needs.

  10. Pipe to FIND or FINDSTR – Filter DIR output: DIR /S | FIND ".log" finds all lines containing ".log". Use for complex filtering.

  11. Use /X to see short names – Display 8.3 short filenames with /X, useful for compatibility with legacy applications or long path issues.

  12. Verify directory before operations – Always run DIR before file operations (DEL, COPY, MOVE) to verify you're in the correct directory and targeting the right files.

Troubleshooting Common Issues

"File Not Found" Error

Problem: DIR displays "File Not Found" when listing a directory.

Cause: The specified directory is empty, contains only hidden/system files, or the path doesn't exist.

Solution:

  • Verify the path exists: DIR parent_directory
  • List hidden files: DIR /A:H
  • List all files including hidden and system: DIR /A
  • Check for typos in the path—use Tab completion

Prevention: Use /A to show all files including hidden and system. Verify paths before running DIR.

"Access is denied" Error

Problem: DIR fails with "Access is denied" when trying to list a directory.

Cause: Insufficient permissions to access the directory, or the directory has restricted NTFS permissions.

Solution:

  • Run Command Prompt as Administrator for system directories
  • Check NTFS permissions with ICACLS directory
  • Verify you're a member of groups with read access
  • For network shares, ensure you have read permissions

Prevention: Run CMD as Administrator when accessing system directories. Check permissions before attempting to list restricted folders.

DIR Output Scrolls Too Fast

Problem: DIR output scrolls past before you can read it in large directories.

Cause: Too many files to fit on one screen.

Solution: Use /P to pause after each screen:

DIR /P

Or pipe to MORE:

DIR | MORE

Or redirect to a file for review:

DIR > listing.txt
TYPE listing.txt | MORE

Prevention: Always use /P for large directories, or redirect output to files for leisurely review.

DIR Doesn't Show Hidden Files

Problem: DIR doesn't display files you know exist (visible in Explorer with "Show hidden files" enabled).

Cause: By default, DIR doesn't show hidden or system files.

Solution: Use /A:H for hidden files:

DIR /A:H

Or /A to show all files including hidden and system:

DIR /A

Prevention: Use /A when you need to see all files regardless of attributes.

DIR Shows Unexpected Files

Problem: DIR lists more files than expected when using wildcards.

Cause: Wildcards match more files than anticipated, or you're in the wrong directory.

Solution:

  • Verify current directory with CD
  • Use more specific wildcards: DIR report-2026-*.txt instead of DIR *.txt
  • Test wildcards incrementally: start with DIR report*, then refine

Prevention: Always verify current directory before using wildcards. Test wildcard patterns incrementally.

Cannot Read Network Directory

Problem: DIR fails when trying to list network paths.

Cause: Network path is inaccessible, server is offline, or you lack permissions.

Solution:

  • Verify network connectivity: PING server
  • Check if share is accessible: NET VIEW \\server
  • Verify permissions on the network share
  • Try accessing with full credentials: NET USE \\server\share /USER:domain\username

Prevention: Verify network connectivity and permissions before attempting to list network directories.

Related Commands

CD – Change Directory

CD changes the current working directory. Use before DIR to navigate to the directory you want to list.

Example:

CD C:\Projects
DIR

Integration: Combine CD and DIR to navigate and explore: CD folder && DIR /W.

TREE – Display Directory Structure

TREE shows a graphical tree of directory structure with ASCII art. Use to visualize subdirectories before exploring with DIR.

Example:

TREE C:\Projects /F

The /F parameter includes files in the tree display.

When to use: Understanding complex directory structures, documenting folder hierarchies, or visualizing project organization.

FIND / FINDSTR – Filter DIR Output

FIND and FINDSTR search for text in DIR output. Use to filter directory listings by filename patterns or attributes.

Example:

DIR /S | FIND ".log"
DIR /S | FINDSTR /I "report.*\.docx"

Integration: Pipe DIR output to FIND or FINDSTR for advanced filtering beyond what DIR parameters provide.

WHERE – Locate Files in PATH

WHERE searches for files in the current directory and PATH environment variable. Use to find executables before navigating to their directories.

Example:

WHERE notepad.exe
WHERE /R C:\Projects *.dll

When to use: Finding executables, locating DLLs, or searching for files across PATH directories.

ATTRIB – Display File Attributes

ATTRIB shows file attributes in a different format than DIR. Use for detailed attribute analysis.

Example:

ATTRIB C:\Windows\System32\*.dll

When to use: Detailed attribute inspection, or when you need to modify attributes after viewing them.

FORFILES – Advanced File Selection

FORFILES selects files based on date, size, or attributes and executes commands on them. Use for date-based file listing beyond DIR's capabilities.

Example:

FORFILES /P C:\Logs /D -30 /C "CMD /C ECHO @path @fsize"

Lists files older than 30 days with their sizes.

When to use: Date-based file selection, automated file processing, or complex filtering scenarios.

Frequently Asked Questions

What does DIR /S do?

DIR /S lists all files in the specified directory and all subdirectories recursively. This parameter is useful for finding files across an entire directory tree, counting total files in a project, or generating complete file inventories. Example: DIR C:\Projects /S shows all files in Projects and all nested subdirectories.

How do I list only files without directories?

Use DIR /A:-D to display only files and exclude directories from the output. The -D attribute filter removes directory entries from the listing, showing only files. Example: DIR /A:-D or DIR C:\Data /A:-D.

What is the difference between DIR and DIR /B?

DIR shows the full listing with headers, file details (date, size, attributes), and summary information (total files, free space). DIR /B uses bare format, displaying only file and directory names without any additional details—ideal for piping to other commands or saving clean file lists.

How do I save DIR output to a file?

Use output redirection: DIR > output.txt creates a new file with the directory listing. Use DIR >> output.txt to append to an existing file instead of overwriting. Example: DIR /S /B > complete-inventory.txt saves a complete recursive file list.

Can DIR search for files by name?

Yes, use wildcards with DIR to search for files: DIR filename.txt finds a specific file, DIR *.txt finds all text files, and DIR file?.txt finds files matching the pattern (? represents one character). Combine with /S for recursive search: DIR /S *.log.

How do I list files sorted by date?

Use DIR /O:D to sort files by date (oldest first) or DIR /O:-D to sort by date in reverse order (newest first). This helps identify recently modified files quickly. Use /T:C to sort by creation date or /T:A for last access date.

What does DIR /A do?

DIR /A displays files with all attributes, including hidden and system files that are normally excluded. Use /A:H for hidden files only, /A:S for system files, /A:D for directories, or /A:-D for files only. Combine attributes: /A:RH shows read-only AND hidden files.

How do I find large files with DIR?

Use DIR /O:-S to sort files by size with largest first. For recursive search: DIR /S /O:-S. To see only files (exclude directories): DIR /A:-D /O:-S. This quickly identifies files consuming the most disk space for cleanup or archiving.

Can I use DIR with network paths?

Yes, DIR works with UNC network paths and mapped network drives: DIR \\server\share or DIR Z:\ for mapped drives. Ensure you have read permissions on the network share. Use /S for recursive listing: DIR \\server\share /S.

What does DIR /P do?

DIR /P pauses the output after each screenful of information, displaying "Press any key to continue..." at the bottom of each screen. This prevents information from scrolling past too quickly in large directories. Essential for viewing large directory listings without redirection.

How do I list only directories?

Use DIR /A:D to display only directories (folders) without files. This shows the directory structure without file clutter. For recursive directory listing: DIR /S /A:D. To see directory names only: DIR /B /A:D.

What is DIR /W?

DIR /W uses wide list format, displaying filenames in multiple columns (typically 5) without dates, sizes, or attributes. This compact format shows more files per screen but omits detailed information. Useful for quick overviews of directory contents.

Quick Reference Card

CommandPurposeExample Use Case
DIRList current directoryView files and folders
DIR /SList recursivelyFind all files in tree
DIR /BBare formatClean output for scripts
DIR /A:HShow hidden filesFind hidden files
DIR /A:-DFiles onlyExclude directories
DIR /O:-SSort by size (largest)Find large files
DIR /O:-DSort by date (newest)Find recent files
DIR /PPause per screenView large directories
DIR *.txtFilter by extensionList specific file types
DIR /S /B > list.txtExport file listCreate inventory

Try DIR Command Now

Ready to practice listing directory contents? Use our Windows Command Simulator to run DIR commands safely in your browser. No installation required—practice DIR, filtering, sorting, and recursive listing in a risk-free environment. Perfect for learning, training, or testing command sequences before running them on production systems.

Explore the full Commands Reference for more Windows CMD utilities, including file management (COPY, MOVE, DEL), directory operations (MKDIR, RMDIR, CD), and system administration commands.

Summary

The DIR command is the essential Windows tool for viewing directory contents from the command line. Use DIR alone to list the current directory, add /S for recursive listing across subdirectories, /A to filter by attributes, and /O to sort results by name, size, date, or extension.

Master DIR parameters for efficient file system navigation and analysis in system administration, development, and power user tasks. Combine /B for bare format in scripts, /P for pagination in large directories, and wildcards for filtering by file type or pattern.

Understanding DIR is fundamental to command-line proficiency in Windows. The command's extensive filtering and sorting options, combined with output redirection capabilities, make it indispensable for file system audits, disk space analysis, and automated inventory generation. Practice DIR operations to build expertise in Windows file system management and troubleshooting.