Skip to content

DIR Windows command

The Windows dir command is a powerful tool used to list files and folders within a specified directory. By simply typing “dir” into the command prompt, users can quickly view a list of all files and subdirectories contained within the current directory. Additionally, the dir command offers various options and parameters to customize the output, such as displaying file sizes, dates, and hidden files. This command is extremely useful for navigating and managing directories efficiently in the Windows operating system.

DIR Syntax:

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

Windows DIR Options:

OptionDescription
/ADisplays files with specified attributes
/BUses bare format (no heading information or summary)
/CDisplay the thousand separator in file sizes
/DSame as wide, but files are list sorted by column
/LUses lowercase
/NNew long list format where filenames are on the far right
/OList by files in sorted order
/PPauses after each screenful of information
/QDisplays the owner of the file
/SDisplays files in specified directory and all subdirectories
/TControls which time field displayed or used for sorting
/WUses wide list format
/XThis displays the short names generated for non-8dot3 file names
/4Displays four-digit years

DIR Parameters:

ParameterDescription
drive:Specifies the drive to list
pathSpecifies the directory or file to list
filenameSpecifies a file or files for the command to process

How to use DIR command:

List all files and folders in the current directory

Terminal window
dir

This command displays a list of all files and folders in the current directory.

List only the directories in the current directory

Terminal window
dir /ad

Using the /ad option, this command lists only the directories in the current directory.

Display detailed information about all files and folders in the current directory

Terminal window
dir /s

The /s option enables the command to display detailed information about all files and folders, including those in subdirectories.

List files and folders in another directory

Terminal window
dir "C:\Users\username\Documents"

By specifying the full path of the directory within double quotes, this command lists the files and folders in the specified location.

List files and folders with a specific extension

Terminal window
dir *.txt

This command lists only the files with a “.txt” extension in the current directory.

Display files and folders sorted by size

Terminal window
dir /os

Using the /os option, this command lists files and folders in the current directory sorted by size, from smallest to largest.

List files and folders with sizes in Kilobytes

Terminal window
dir /s /k

By combining the /s and /k options, this command displays files and folders in the current directory with their sizes in kilobytes.

List files and folders in a tree-like structure

Terminal window
dir /s /p

The /s and /p options together create a tree-like structure for listing files and folders in the current directory and its subdirectories.

How do I use dir in CMD?

To use the dir command in CMD, execute the following command:

Terminal window
dir

How can I list all files in a directory using dir in CMD?

To list all files in a directory, including hidden files, use the following command:

Terminal window
dir /a

How do I display file size with dir in CMD?

To display file size along with other information, use the command:

Terminal window
dir /s

How to list contents of a directory recursively with dir in CMD?

To list the contents of a directory and all its subdirectories, run the following command:

Terminal window
dir /s /b

How can I save the directory listing to a text file using dir in CMD?

To save the directory listing to a text file, use the following command:

Terminal window
dir /s /b > directory_listing.txt

How to list directories only with dir in CMD?

To list only directories and not files, use the following command:

Terminal window
dir /ad

How do I sort files by size using dir in CMD?

To sort files by size in descending order, execute the following command:

Terminal window
dir /os -s

How can I filter files with a specific extension using dir in CMD?

To filter files with a specific extension, such as .txt, use the following command:

Terminal window
dir *.txt

How do I display detailed file information with dir in CMD?

To display detailed file information, including attributes and timestamps, use the following command:

Terminal window
dir /Q

Applications of the DIR Command

  • List files and directories
  • Display file and directory details
  • List hidden files and directories
  • List files and directories in a specific directory
  • Display file and directory information in a specified format