DIR: Displays a list of files and subdirectories in a directory.
The command: "DIR" is on Windows 11, 10, .. available
The examples for the command "DIR"
command in Windows Command Prompt is used to display information about files and directories. Here are some examples with comments:
Example 1: Show contents of current directory:
This command displays the contents of the current directory, including files and subdirectories.
Example 2: Show contents of a specific directory:
DIR C:\Path\Destination directory
The contents of the directory "C:\Path\Target directory"
are displayed here.
Example 3: Show content with details:
YOU /A /W
This command displays the contents of the current directory, including details such as file size and modification date. `/A`
also shows hidden files, and `/W`
shows the information in a wider column view.
Example 4: Display content with subdirectories (recursively):
Here the contents of the current directory including all subdirectories are displayed recursively.
Example 5: Show only file names, no details:
This command only displays the file names in the current directory, without details such as size and date. Useful in scripts or if you're just interested in the filenames.
Example 6: Show content sorted by date:
The contents of the current directory are displayed here, sorted by date.
Example 7: Show only directories:
This command only displays the directories in the current directory, not the files.
Example 8: Save content to a text file:
DIR > directory list.txt
This command saves the contents of the current directory to a text file named "directorylist.txt"
Example 9: Show help:
This command displays help and information about the available options for the `DIR`
command provides a variety of options to customize the content displayed. You can access the help using `DIR /?`
for more details. Note that some options, such as `/S`
, can significantly affect the output.
"DIR" Excerpt from Microsoft Windows Help
Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.
Displays a list of files and subdirectories in a directory.
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
Specifies drive, directory, and/or files to list.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years
Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.
Important information, tips for the "DIR" command
There are a few important points to note when using the `DIR`
command in the Windows Command Prompt:
You can use wildcards ( and ?) to display files or directories in a specific pattern. For example, `DIR .txt`
displays all text files in the current directory.
2. Directory structure:
If you use `/S`
, the command will display the contents of all subdirectories recursively.
3. Show hidden files:
You can use `/A`
to show hidden files. `/A:H`
only shows hidden files.
4. Show Details: `/W`
displays files and directories in a wider column view, while `/O`
changes the sort order. For example, `DIR /O:D`
shows the files sorted by date.
5. Show filenames only: `/B`
displays only the filenames, without any additional information.
6. File Attributes: `/A`
can also be used to select files based on attributes (e.g., `/A:-R`
only displays files that are not read-only).
7. Redirect output to a file:
You can redirect the output of `DIR`
to a file for storage or further processing.
DIR > directory list.txt
8. Show Help: `DIR /?`
displays help and information about the available options for the `DIR`
Note that the `DIR`
command allows viewing files and directories in a directory. If you want to perform more specific operations such as copying, deleting, or moving, you could use additional commands such as `COPY`
, or `MOVE`