Displays a list of the files and subdirectories that are in the directory you specify.
When you use DIR without parameters or switches, it displays the disk's volume label and serial number; one directory or filename per line, including the filename extension, the file size in bytes, and the date and time the file was last modified; and the total number of files listed, their cumulative size, and the free space (in bytes) remaining on the disk.
DIR [drive:][path][filename] [...] [/A[[:]attributes]] [/B] [/C[H]] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/V] [/W] [/X] [/Z] [/4]
For information about environment variables that affect the way
DIR works, see %DIRCMD%.
For information about displaying the directory structure of a path or disk, see the TREE command.
For information about compressing disks, see the DRVSPACE command.
For information about compressing disks, see the DRVSPACE command.
You can also list files by XCOPY /L. NT3.5
You can show size of multiple subfolders by DIRUSE command. NT4
Equivalent UNIX command is:
Browsing LAN directories can be slow.
You can use wildcards (* and ?) to display a listing of a subset of files and subdirectories. For an example illustrating the use of a wildcard, see the Example.
if you specify the /A switch with more than one value in attributes, DIR displays the names of only those files with all the specified attributes. For example, if you specify the /A switch with the R and -H values for attributes by using either /A:R-H or /AR-H, DIR displays only the names of read-only files that are not hidden.
If you specify more than one sortorder value, DIR sorts the filenames by the first criterion first, then by the second criterion, and so on. For example, if you specify the /O switch 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 displays the final result. The alphabetic sorting by extension causes filenames with no extensions to appear first, then directory names, then filenames with extensions.
The date and time formats used by DIR depend on the country setting you use in your CONFIG.SYS file. If you don't use the COUNTRY command, the formats are those for the United States.
When you use a redirection symbol (>) to send DIR output to a file or a pipe (|) to send DIR output to another command, use the /A:-D and /B switches to list only the filenames. You can use the filename parameter with the /B and /S switches to specify that DIR is to search the current directory and its subdirectories for all filenames that match filename. DIR lists only the drive letter, directory name, filename, and filename extension, one path per line, for each filename it finds.
Before using a pipe for redirection, you should set the TEMP environment variable in your AUTOEXEC.BAT file. Otherwise, the temporary file will appear in the directory listing.
You can preset DIR parameters and switches by including the SET command with the %DIRCMD% environment variable in your AUTOEXEC.BAT file. You can use any valid combination of DIR parameters and switches with the SET %DIRCMD% command, including the location and name of a file.
For example, to use the %DIRCMD% environment variable to set the wide display format (/W) as the default format, include the command in your AUTOEXEC.BAT file:
For a single use of the DIR command, you can override a switch set by using the %DIRCMD% environment variable. To do so, you use the same switch on the DIR command-line, but you must also precede the switch letter with a minus sign:
You can change the %DIRCMD% default settings by typing the SET command at the command prompt with a new parameter or switch after the equal sign (=). The new default settings are effective for all subsequent DIR commands until you use SET %DIRCMD% again on the command line or until you restart the operating system.
To clear all default settings, type:
You can view the current settings of the %DIRCMD% environment variable by typing:
The operating system displays a list of environment variables and their settings. For more information about setting environment variables, see the SET command.
DIR noted the date a file was created or changed, it ignored the time.
UNDOCUMENTED. DIR, (DIR followed by a comma) Displays ALL files in the current directory, including hidden and system files.
This appears only to work with v5.0 and v6.0. With v3.30, it doesn't display either IO.SYS, MSDOS.SYS (both with S, H and R attribs) or a test file with A and H attribs.
With v5.0, it displayed a test file with H and A, but would not display IO.SYS or MSDOS.SYS with S, H and R. This isn't surprising actually, since S alone (without H) will prevent inclusion of a file in a normal DIR.
Not tested with v4.0 or v4.01. Not supported by JP Software's 4DOS.
Does not work in v7.00, the DOS that comes with Win95 and Win98.
Suppose you want to display all files and directories in a directory, including hidden or system files. To specify this display, type:
Suppose you want DIR to display one directory listing after another, until it has displayed the listing for every directory on the disk in the current drive. Suppose also that you want DIR to alphabetize each directory listing, display it in wide format, and pause after each screen. To specify such a display, be sure the root directory is the current directory and then type:
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 filenames in each subdirectory in the directory tree.
To alter the preceding example so that DIR displays the filenames and extensions but omits the directory names, type:
DIR /S /W /O /P /A:-D
To print a directory listing, type the redirection symbol and PRN after any form of the DIR command:
DIR > prn
When you specify PRN on the DIR command-line, the directory listing 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 filename. A path is also accepted on the command-line. 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, the operating system creates it, unless the directory RECORDS also does not exist. In that case, the operating system displays the message:
File creation error
To display a list of all the filenames 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 filenames in each directory and pauses each time the screen fills, until you press a key to continue.