dir
Displays a list of a directory's files and subdirectories. Used without parameters, dir 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, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.
Syntax
Parameters
Remarks
-
Using multiple FileName parameters
You can use multiple FileName parameters. Separate file names with spaces, commas, or semicolons. You can use wildcard characters (that is, ? and *) in FileName to display a group of files.
- Using wildcard characters
You can use wildcard characters, such as an asterisk (*) or a question mark (?), to represent one or more characters of a file name and to display a subset of files or subdirectories.
Asterisk (*): Use the asterisk as a substitute for any string of characters. For example, typing:
- dir *.txt lists all files in the current directory with extensions that begin with .txt, such as .txt, .txt1, .txt_old.
- dir read*.txt lists all files in the current directory that begin with "read" with extensions that begin with .txt, such as .txt, .txt1, .txt_old.
- dir read*.* lists all files in the current directory that begin with "read" with any extension.
Keep in mind that the asterisk wildcard always uses short file name mapping, so you might get unexpected results. For example, the following directory contains 2 files, t.txt2 and t97.txt:
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 using its short name map T97B4~1.TXT. Similarly, typing del t97* would delete both files.
Question mark (?): Use the question mark as a substitute for a single character in a name. For example, typing:
- dir read???.txt lists any files in the current directory with the .txt extension that begin with "read" followed by up to three characters, including Read.txt, Read1.txt, Read12.txt, Read123.txt, and Readme1.txt, but not Readme12.txt.
- Specifying file display attributes
If you use /a with more than one value in Attributes, dir displays the names of only those files with all the specified attributes. For example, if you use /a with r and -h for attributes by using either /a:r-h or /ar-h, dir displays only the names of read-only files that are not hidden.
- Specifying file name sorting
If you specify more than one SortOrder value, dir sorts the file names by the first criterion first, then by the second criterion, and so on. For example, if you use /o with the e and -s values for SortOrder by using either /o:e-s or /oe-s, dir sorts the names of directories and files by extension, with the largest first, and then displays the final result. The alphabetic sorting by extension causes file names with no extensions to appear first, then directory names, and then file names with extensions.
- Using redirection symbols and pipes
When you use a redirection symbol (>) to send dir output to a file or a pipe (|) to send dir output to another command, use /a:-d and /b to list the file names only. You can use FileName with /b and /s to specify that dir is to search the current directory and its subdirectories for all file names that match FileName. Dir lists only the drive letter, directory name, file name, and file name extension, one path per line, for each file name it finds. Before you use a pipe for redirection, you should set the TEMP environment variable in your Autoexec.nt file.
-
Presetting dir parameters
You can preset dir parameters by including set with the DIRCMD environment variable in your Autoexec.nt file. You can use any valid combination of dir parameters with set dircmd, including the location and name of a file.
For example, to use the DIRCMD environment variable to set the wide display format (that is, /w) as the default format, type the following command in your Autoexec.nt file:
set dircmd=/w
For a single use of the dir command, you can override a parameter by using the DIRCMD environment variable. To do so, type the parameter that you want to override at the dir command prompt, preceding the parameter with a minus sign. For example:
dir /-w
To change the DIRCMD default settings, type:
set=NewParameter
The new default settings are effective for all subsequent dir commands until you use set dircmd again or until you restart your computer.
To clear all default settings, type:
set dircmd=
To view the current settings of the DIRCMD environment variable, type:
set
Set displays a list of environment variables and their settings. For more information about setting environment variables, see Related Topics.
- The dir command, with different parameters, is available from the Recovery Console.
Examples
dir /s/w/o/p
Dir lists the name of the root directory, the names of the subdirectories of the root directory, and the names of the files in the root directory, including extensions. Then, dir lists the subdirectory names and 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:
ir > prn
When you specify prn, the directory list is sent to the printer 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
Dir displays, in wide format, an alphabetized list of the matching file names in each directory and pauses each time the screen fills up, until you press a key to continue.
Formatting legend
Format | Meaning |
Italic | Information that the user must supply |
Bold | Elements that the user must type exactly as shown |
Ellipsis (...) | Parameter that can be repeated several times in a command line |
Between brackets ([]) | Optional items |
Between braces ({}); choices separated by pipe (|). Example: {even|odd} | Set of choices from which the user must choose only one |
Courier font | Code or program output |