Home > Commands A-M > Commands Da-Dr

DIR


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

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.


Syntax

DIR /?

DIR [drive:][path][filename] [...] [/A[[:]attributes]] [/B] [/C[H]] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/V] [/W] [/X] [/Z] [/4]


Parameters
drive: (v1.0 Win95 NT3.5)
Specifies the drive for which you want to see a listing.
path (v2.0 Win95 NT3.5)
Specifies the directory for which you want to see a listing.
filename (v1.0 Win95 NT3.5)
Specifies a particular file or group of files for which you want to see a listing.
[...] (NT2000)
You can use multiple file_name parameters. Separate file_names with spaces, commas, or semicolons. You can use wildcard characters (? and *) in file_name to display a group of files.

Switches
/? (NTXP)
Display help.
/A[[:] attributes] (v5.0 Win95 NT3.5)
Displays only the names of those directories and files with the attributes you specify. If you omit this switch, DIR displays the names of all files except hidden and system files. The list describes each of the values you can use for attributes. The colon (:) is optional. Use any combination of these values, and do not separate the values with spaces:
/B (v5.0 Win95 NT3.5)
Lists each directory name or filename, one per line (including the filename extension). This switch displays no heading information and no summary, bare. The /B switch overrides the /C[H] or /W switch.
/C (NT4)
Include thousands separator in file sizes.
/-C (NT4)
Don't include thousands separator in file sizes.
/C[H] (v6.2 through v7.00 Win95 ONLY)
Displays the compression ratio of files compressed using DoubleSpace or DriveSpace, based on an 8K cluster size. The /C[H] switch is ignored when used with the /B or /W switch.
H
The optional H switch displays the compression ratio of files compressed using DoubleSpace or DriveSpace, based on the cluster size of the host drive.
/D (NT3.5)
Wide List format, sorted by vertical column.
/L (v5.0 Win95 NT3.5)
Displays unsorted directory names and filenames in lowercase. This switch does not convert extended characters to lowercase.
/N (NT3.5)
Long List format, filenames on far right.
/O[[:] sortorder]
Controls the order in which DIR sorts and displays directory names and filenames. If you omit this switch, DIR displays the names in the order in which they occur in the directory. If you use this switch without specifying sortorder, DIR displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:) is optional. The list describes each of the values you can use for sortorder. Use any combination of the values, and do not separate these values with spaces:
/P (v1.0 Win95 NT3.5)
Displays one screen of the listing at a time. To see the next screen, press any key.
/Q (NT2000)
Display owner of the file.
/S (v5.0 Win95 NT3.5)
Lists every occurrence, in the specified directory and all subdirectories, of the specified filename.
/T[[:] timefields] (NT3.5)
Time field used to display and sort:
/V (v7.00 Win95)
Verbose mode. Also displays attributes, date last accessed, and disk space allocated. The /V switch overrides the /4 switch.
/W (v1.0 Win95 NT3.5)
Displays the listing in wide format, with as many as five filenames or directory names on each line. The /W switch is ignored when used with the /B switch. NT also sorts horizontally.
/X (NT3.5)
Long List format, filenames on far right (/N), includes short (8dot3) filename before long filename.
/Z (v7.00 Win95)
UNDOCUMENTED. Do not display long filenames. Explicitly specifying the path or use with /B or /S may result in short (8dot3) path(s) or filename(s).
/4 (v7.00 Win95 NT2000)
UNDOCUMENTED in v7.00 and Win95.
DOCUMENTED in v7.10 and Win98.
Display four-digit years. The /4 switch is ignored when used with the /V switch.

Related

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:
ls


Notes
Browsing LAN directories can be slow

Browsing LAN directories can be slow.


Using wildcards with DIR

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.


Specifying file display attributes

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.


Specifying filename sorting

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.


Setting date and time formats

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.


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 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.


Presetting DIR parameters and switches

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:

    SET dircmd=/W

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:

    DIR /-W

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:

    SET dircmd=

You can view the current settings of the %DIRCMD% environment variable by typing:

    SET

The operating system displays a list of environment variables and their settings. For more information about setting environment variables, see the SET command.


Dos 1.0 note

DIR noted the date a file was created or changed, it ignored the time.


Undocumented parameters and switches

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.


Examples

Suppose you want to display all files and directories in a directory, including hidden or system files. To specify this display, type:

    DIR /A

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.


Errorlevels

none.


Availability
Internal
DOS
v1.0 v1.05 v1.1 v1.11 v1.24 v1.25 v1.85 v2.0 v2.01 v2.05 v2.10 v2.11 v2.11R v2.12 v2.2 v2.25 v3.0 v3.20 v3.05 v3.1 v3.21 v3.25 v3.30 v3.3A v3.3R v3.3T v3.31 v3.40 v4.0 v4.01 v4.01A v5.0 v5.0A v5.00.02 v5.001A v5.01 v5.02 v6.0 v6.10 v6.2 v6.21 v6.22 v6.23 v7.00 v7.0R1 v7.10 v8.00
Windows
Win95 Win98 WinME
Windows NT
NT3.5 NT4 NT2000 NTXP NT2003