dir (original) (raw)

Displays a list of a directory's files and subdirectories. If used without parameters, this command displays the disk's volume label and serial number, followed by a list of directories and files on the disk (including their names and the date and time each was last modified). For files, this command displays the name extension and the size in bytes. This command also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.

The dir command can also run from the Windows Recovery Console, using different parameters. For more information, see Windows Recovery Environment (WinRE).

Syntax

dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r]

Parameters

Parameter Description
[:][] Specifies the drive and directory for which you want to see a listing.
[] Specifies a particular file or group of files for which you want to see a listing.
/p Displays one screen of the listing at a time. To see the next screen, press any key.
/q Displays file ownership information.
/w Displays the listing in wide format, with as many as five file names or directory names on each line.
/d Displays the listing in the same format as /w, but the files are sorted by column.
/a[[:]] Displays only the names of those directories and files with your specified attributes. If you don't use this parameter, the command displays the names of all files except hidden and system files. If you use this parameter without specifying any attributes, the command displays the names of all files, including hidden and system files. The list of possible attributes values are:d - Directoriesh - Hidden filess - System filesl - Reparse pointsr - Read-only filesa - Files ready for archivingi - Not content indexed filesYou can use any combination of these values, but don't separate your values using spaces. Optionally you can use a colon (:) separator, or you can use a hyphen (-) as a prefix to mean, "not". For example, using the -s attribute won't show the system files.
/o[[:]] Sorts the output according to sortorder, which can be any combination of the following values:n - Alphabetically by namee - Alphabetically by extensiong - Group directories firsts - By size, smallest firstd - By date/time, oldest firstUse the - prefix to reverse the sort orderMultiple values are processed in the order in which you list them. Don't separate multiple values with spaces, but you can optionally use a colon (:).If sortorder isn't specified, dir /o lists the directories alphabetically, followed by the files, which are also sorted alphabetically.
/t[[:]] Specifies which time field to display or to use for sorting. The available timefield values are:c - Creationa - Last accessedw - Last written
/s Lists every occurrence of the specified file name within the specified directory and all subdirectories.
/b Displays a bare list of directories and files, with no additional information. The /b parameter overrides /w.
/l Displays unsorted directory names and file names, using lowercase.
/n Displays a long list format with file names on the far right of the screen.
/x Displays the short names generated for non-8dot3 file names. The display is the same as the display for /n, but the short name is inserted before the long name.
/c Displays the thousand separator in file sizes. This is the default behavior. Use /-c to hide separators.
/4 Displays years in four-digit format.
/r Display alternate data streams of the file.
/? Displays help at the command prompt.
C:\test>dir /x  
Volume in drive C has no label.  
Volume Serial Number is B86A-EF32  
Directory of C:\test  
11/30/2004  01:40 PM <DIR>  .  
11/30/2004  01:40 PM <DIR> ..  
11/30/2004  11:05 AM 0 T97B4~1.TXT t.txt2  
11/30/2004  01:16 PM 0 t97.txt  

You might expect that typing dir t97\* would return the file t97.txt. However, typing dir t97\* returns both files, because the asterisk wildcard matches the file t.txt2 to t97.txt by using its short name map T97B4~1.TXT. Similarly, typing del t97\* would delete both files.

Examples

To display all directories one after the other, in alphabetical order, in wide format, and pausing after each screen, make sure that the root directory is the current directory, and then type:

dir /s/w/o/p

The output lists the root directory, the subdirectories, and the files in the root directory, including extensions. This command also lists the subdirectory names and the file names in each subdirectory in the tree.

To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type:

dir /s/w/o/p/a:-d

To print a directory listing, type:

dir > prn

When you specify prn, the directory list is sent to the printer that is attached to the LPT1 port. If your printer is attached to a different port, you must replace prn with the name of the correct port.

You can also redirect output of the dir command to a file by replacing prn with a file name. You can also type a path. For example, to direct dir output to the file dir.doc in the Records directory, type:

dir > \records\dir.doc

If dir.doc does not exist, dir creates it, unless the Records directory does not exist. In that case, the following message appears:

File creation error

To display a list of all the file names with the .txt extension in all directories on drive C, type:

dir c:\*.txt /w/o/s/p

The dir command displays, in wide format, an alphabetized list of the matching file names in each directory, and it pauses each time the screen fills until you press any key to continue.