Purpose:Display information about files and subdirectories

 

Format:DIR [ranges] [options] [file...]

 

rangesone or more ranges
optionsone or more file selection or report format options
fileThe file, directory, or list of files or directories to display.

 

/1

1 column output

/L

Lower case

/2

2 column output

/M

suppress footer

/4

4 column output

/N[desfhjlmvz]

New format or disable options

/:

show streams

/O

Order

/A

Attribute select

/P[n]

Pause

/B

Bare (name only)

/Q

show owner

/C

show Compression

/R

disable wrap

/CD:...

COLORDIR string

/Sn

show Subdirectories to depth n

/D

Disable color coding

/T

show aTtributes

/E

upper case

/T:

time type

/F

Full path

/U

show summary information

/G[:n]

allocated size

/V

Vertical sort

/H

Hide dots

/W

Wide

/HL

Show hard links

/X

show short names

/I"text"

description range

/Z

use FAT format

/J

Justify names

/\

Trailing \ for directory names

/K

suppress header



 

See also: ATTRIB, DESCRIBE, PDIR, SELECT, and SETDOS.

 

File Selection

 

Supports extended wildcards, ranges, multiple file names, and include lists.

 

Internet:  Can be used with HTTP and FTP servers.

 

Usage:

 

DIR can be used to display information about files from one or more directories (local or remote), in a wide range of formats. Depending on the options chosen, you can display the file name, attributes, and size; the time and date of the last change to the file; the file description; and the file's compression ratio. You can also display information in 1, 2, 4, or 5+ columns, sort the files several different ways, use color to distinguish file types, and pause after each full screen.

 

If you want to produce customized output that will be subsequently parsed by another program or batch file, or if you need a special-purpose directory display, see the PDIR command. DIR and PDIR are related, but they do not have identical switches and they are not intended to produce identical output.

 

The various DIR displays are controlled through options or switches. The best way to learn how to use the many options available with the DIR command is to experiment. You will soon know which options you want to use regularly. You can select those options permanently by using the ALIAS command.

 

For example, to display all the files in the current directory, in 2 columns, sorted vertically (down one column then down the next), and with a pause at the end of each page:

 

dir /2/p/v

 

To set up this format as the default, using an alias:

 

alias dir=*dir /2/p/v

 

When you use DIR on an LFN drive, you must quote any file names which contain white space or special characters.

 

DIR sets three internal variables:

 

%_dir_dirsThe number of directories displayed
%_dir_filesThe number of files displayed
%_dir_errorsThe number of errors

 

The following sections group DIR's features together in several categories. Many of the sections move from a general discussion to more technical material. If you find some of the information in a category too detailed for your needs, feel free to skip to the beginning of the next section. The sections are:

 

Onestep        Selecting Files

Onestep        Default DIR Output Format

Onestep        Switching Formats

Onestep        Multiple Column Displays

Onestep        Color-Coded Directories

Onestep        Redirected Output

Onestep        Other Notes

Onestep        Options

Onestep        FTP usage

 

Selecting Files

 

DIR can display information about a single file or about several, dozens, hundreds, or thousands of files at once. To display information about a single file, just add the name of the file to the DIR command line:

 

dir january.wks

 

The simplest way to view information about several files at once is to use wildcards. DIR can work with the normal wildcard characters (* and ?) and the extended wildcards. For example to display all of the .WKS files in the current directory:

 

dir *.wks

 

To display all .TXT files whose names begin with A, B, or C:

 

dir [abc]*.txt

 

If you don't specify a filename, DIR defaults to * on LFN drives, and *.* on drives which do not support long file names. This default displays all non-hidden files and subdirectories in the current directory. If you specify a filename for a non-LFN drive which includes some wildcards, and does not include an extension, DIR will append .* to it to match all extensions.

 

If you link two or more filenames together with spaces, DIR will display all of the files that match the first name and then all of the files that match the second name. You may use a different drive and path for each filename. This example lists all of the .WKS and then all of the .WK1 files in the current directory:

 

dir *.wks *.wk1

 

If you use an include list to link multiple filenames, DIR will display the matching filenames in a single listing. Only the first filename in an include list can have a path; the other files must be in the same path. This example displays the same files as the previous example, but the .WKS and .WK1 files are intermixed:

 

dir *.wks;*.wk1

 

You can include files in the current or named directory plus all of its accessible subdirectories by using the /S option. This example displays all of the .WKS and .WK1 files in the D:\DATA directory and each of its subdirectories:

 

dir /s d:\data\*.wks;*.wk1

 

You can also select files by their attributes by using the /A option. For example, this command displays the names of all of the subdirectories of the current directory:

 

dir /a:d

 

Finally, with the /I option, DIR can select files to display based on their descriptions (see DESCRIBE for more information on file descriptions). DIR will display a file if its description matches the text after the /I switch. The search is not case sensitive. You can use wildcards and extended wildcards as part of the text. For example, to display any file described as a "Test File" you can use this command:

 

dir /i"test file"

 

If you want to display files that include the words "test file" anywhere in their descriptions, use extended wild cards like this:

 

dir /i"*test file*"

 

To display only those files which do not have descriptions, use:

 

dir /I"[]"

 

In addition, you can use ranges to select or exclude specific sets of files. For example, to display all files modified in the last week, all files except those with a .BAK extension, and all files over 500 KB in size:

 

dir /[d-7]

dir /[!*.bak]

dir /[s500K]

 

You can mix any of these file selection techniques in whatever ways suit your needs.

 

Default DIR Output Format

 

DIR's output varies based on the type of volume or drive on which the files are stored. If the volume supports long file names, the default DIR format contains 4 columns: the date of the last file modification or write, the time of last write, the file size in bytes, and the file name. The name is displayed as it is stored on the disk, in upper, lower, or mixed case. DIR will wrap filenames from one line to the next if they are too long to fit the width of the display. The standard output format is:

 

Volume in drive C is unlabeled      Serial number is 3aaf:c891

Directory of  C:\release\version28\*

 

2021-06-30   0:39         <DIR>    .

2021-06-30   0:39         <DIR>    ..

2021-06-25  11:30         <DIR>    tcmd

2021-06-25  23:07       4,801,840  tcmd.exe

 

(See Switching Formats below for information on changing the standard long filename format to allow room for file descriptions.)

 

On FAT volumes which do not support long file names, the default DIR format contains 5 columns: the file name, the file size in bytes, the date of the last write, the time of the last write, and the file's description. File names are listed in lower-case; directory names in upper case:

 

Volume in drive C is C - BOOTUP    Serial ...

Directory of  C:\*

 

.           <DIR>        6-24-21  12:17

..          <DIR>        6-24-21  12:17

TEST         <DIR>       6-01-21  16:21

jpstree.idx    196967    6-28-21  17:57 JP fuzzy directory index

 

DIR's output is normally sorted by name, with directories listed first. You can change the sort order with the /O option. For example, these two commands sort the output by date. The first command lists the oldest file first; the second command lists the oldest file last:

 

dir /o:d

dir /o:-d

 

When displaying file descriptions, DIR wraps long lines to fit on the screen. DIR displays a maximum of 40 characters of text in each line of a description (unless your screen width allows a wider display). If you disable description wrapping with the /R option, the description is truncated at the right edge of the screen, and a right arrow is added at the end of the line to alert you to the existence of additional description text.

 

DIR's default output is sorted. It displays directory names first, with "<DIR>" inserted instead of a file size, and then filenames. DIR assumes that sequences of digits should be sorted numerically (for example, the file DRAW2 is listed before DRAW03 because 2 is numerically smaller than 03), rather than strictly alphabetically (where DRAW2 would come second because "2" follows "0" in alphanumeric order). You can change the sort order with the /O option. When DIR displays file names in a multi-column format, it sorts file names horizontally unless you use the /V option to display vertically sorted output.

 

DIR's display can be modified in many ways to meet different needs. Most of the following sections describe the various ways you can change DIR's output format.

 

Switching Formats

 

On volumes which support long file names, you can force DIR to use a FAT-like format (file name first, followed by file information) with the /Z option. If necessary, DIR /Z truncates long file names on LFN drives, and adds a right arrow to show that the name contains additional characters.

 

The standard LFN output format does not provide enough space to show descriptions along with file names. Therefore, if you wish to view file descriptions as part of the DIR listing on a volume which supports long file names, you must use the /Z option.

 

DIR will display the alternate, short file names for files with long file names if you use the /X option. Used alone, /X causes DIR to display names in 2 columns after the size, time, and date: one column for alternate or short file names and the other for long file names. If a file does not have a short or alternate name which is different from the long filename, the first filename column is empty.

 

If you use /X and /Z together, DIR will display the short or alternate file names in the FAT-style display format.

 

If you use the /B option, DIR displays just file names and omits the file size, time stamp, and description for each file, for example:

 

[c:\] dir w* /b

WINDOWS

WINNT

WINALIAS

WINENV.BTM

.....

 

There are several ways to modify the display produced by /B. The /F option is similar to /B, but displays the full path and name of each file, instead of just its name. To view the same information for a directory and its subdirectories use /B /S or /F /S. You can use /B /X to display the short name of each file, with no additional information.

 

Multiple Column Displays

 

DIR has three options, /2, /4, and /W, that create multi-column displays.

 

The /2 option creates a 2-column display. On drives which support long filenames, only the name of each file is displayed, with directory names placed in square brackets to distinguish them from file names. On drives which do not support long filenames, or when /Z or /X is used (see below), the display includes the short name, file size, and time stamp for each file.

 

The /4 option is similar to /2, but displays directory information in 4 columns. On drives which do not support long filenames, or when /Z or /X is used (see below), the display shows the file name and the file size in kilobytes (KB) or megabytes (MB), with "<D>" in the size column for directories.

 

The /W option displays directory information in 5 or more columns, depending on your screen width. Each entry in a DIR /W display contains either the name of a file or the name of a directory. Directory names are placed in square brackets to distinguish them from file names.

 

If you use one of these options on a drive that supports long file names, and do not select an alternate display format with /Z or /X, the actual number of columns will be based on the longest name to be displayed and your screen width, and may be less than the number you requested (for example, you might see only three columns even though you used /4). If the longest name is too long to fit in on a single line the display will be reduced to one column, and each name will be wrapped, with "extra" blank lines added so that each name takes the same number of lines.

 

On LFN drives you can use /Z with any of the multi-column options to create a FAT-format display, with long names truncated to fit in the available space. If you use /X, the FAT-format display is also used, but short names are displayed (rather than truncated long names). The following table summarizes the effects of different options when using TCC on an LFN drive:

 


default or /1

/2 or /4 columns

/W (wide)

Normal

date, time, size, LFN

2 - 4 columns, LFNs only

No. of columns based on longest LFN

/Z (FAT)

truncated LFN, size, date, time

2 - 4 columns, truncated LFN plus date, time,  size

5+ columns, truncated LFNs only

/X (SFN)

date, time, size, SFN, LFN

2  - 4 columns, SFNs plus date, time, size

5+ columns, SFNs only

/X /Z

SFN, size, date, time

(Same as /X)

(Same as /X)

 

 

Color-Coded Directories

 

DIR can display each file name and the associated file information in a different color, depending on the file's extension, attributes, or matching range.

 

To choose the display colors, you must either use the SET command to create an environment variable called COLORDIR, or use the Directory Colors configuration option. If you use neither the variable nor the configuration option, DIR will use the default screen colors for all files.

 

If you use the COLORDIR variable, it will override the Directory Colors option. You may find it useful to use the COLORDIR variable for experimenting, then to set permanent directory colors with the Directory Colors option.

 

The format for both the COLORDIR environment variable and the Directory Colors option is:

 

ext ... :ColorName; ...

 

where "ext" is either a file extension (which may include wildcards), one or more of the following file types:

 

type

files affected

ARCHIVE

Files with archive attribute set (modified since the last backup)

COMPRESSED

Compressed files

DIRS

Directories

ENCRYPTED

Encrypted files

HIDDEN

Hidden files

JUNCTION

Junctions or symbolic links

NORMAL

File with no attribute set

NOTINDEXED

Files whose content is not indexed

OFFLINE

Offline files

RDONLY

Read-only files

SPARSE

Sparse files

SYSTEM

System files

TEMPORARY

temporary files

 

or a range (size, date, time, description, owner, and/or exclusion), or a file subsystem type:

 

EXETYPE_WIN32GUIWindows x86 GUI app
EXETYPE_WIN32CUIWindows x86 console app
EXETYPE_WIN64GUIWindows x64 GUI app
EXETYPE_WIN64CUIWindows x64 console app
EXETYPE_DOSDOS (16-bit) app (obsolete)
EXETYPE_POSIXPOSIX app (obsolete)
EXETYPE_EFIEFI app

 

and "ColorName" is any valid color name (see Colors and Color Names for information on color names). Specifying a subsystem type will significantly slow down the directory display, as TCC-RT has to read the header of each file to find a match.

 

Note that if a file uses one of the reserved file type names shown above as its extension (e.g. xyz.hidden) , that file will receive the color defined for the file type.

 

Unlike most color specifications, the background portion of the color name may be omitted for directory colors. If you don't specify a background color, DIR will use the current screen background color.

 

For example, to display .COM and .EXE files in red on the current background, .C and .ASM files in bright cyan on the current background, read-only files in green on white, and everything else in the default color:

 

set colordir=exe:red; c asm:bright cyan; rdonly:green on white

 

To display 32-bit console apps in bright green and 64-bit console apps in bright red:

 

set colordir=EXETYPE_WIN32CUI:bri green;EXETYPE_WIN64CUI:bri red

 

Extended wildcards can be used in directory color specifications. For example, to display .BAK, .BAX, and .BAC files in red, and everything else in the default color:

 

set colordir=BA[KXC]:red

 

You can combine attribute tests with the .and. / .or. / .xor. / .not. keywords. For example, to display directories that are also hidden in blue:

 

set colordir=dirs .and. hidden:blue

 

COLORDIR processes the line from left to right, and does not support parentheses.

 

Redirected Output

 

The output of the DIR command, like that of most other internal commands, can be redirected to a file, printer, serial port, or other device. However, you may need to take certain DIR options into account when you redirect DIR's output.

 

DIR wraps both long file names and file descriptions at the width of your display. Its redirected output will also wrap at the screen width. Use the /R option if you wish to disable wrapping of long descriptions.

 

If you redirect a color-coded directory to a file or a character device, DIR will remove the color data as it sends the directory information to a file.

 

To redirect DIR output to the clipboard, use CLIP: as the output device name, for example:

 

dir *.exe > clip:

 

FTP Usage

 

You can display directories on FTP servers. For example:

 

dir ftp://ftp.microsoft.com/

 

You can also use the IFTP command to start an FTP session on a server, and then use a simplified syntax to specify the files and directories you want.

 

HTTP Usage

 

DIR has limited support for HTTP & HTTPS filenames. DIR will display the filename, size, and date/time (for last write only). Wildcards are not supported (this is an HTTP limitation, not TCC-RT).

 

Other Notes

 

If you have selected a specific country code for your system, DIR will display the date in the format for that country. The default date format is U.S. (mm-dd-yy). The separator character in the file time will also be affected by the country code. Thousands and decimal separators in numeric displays are affected by the country code, and by the ThousandsChar and DecimalChar settings selected with the configuration dialogs or in the .INI file.

 

DIR can generally display any file date between January 1, 1980 and December 31, 2099 if the date is supplied properly by the operating system.

 

If you are using NTFS disk compression, you can use the /C switch to view the amount of compression achieved for each file. When you do, the compression ratio is displayed instead of the file's description. You can also sort the display by compression ratios with the /O:c switch. Details for both switches are in the Options section below. /C and /O:c will be ignored for uncompressed drives. /C will not display compression ratios on drives that support long file names unless you also use /Z to switch to the old-style short filename format.

 

If the OFFLINE attribute is set, DIR will display the file size enclosed in parentheses (for compatibility with CMD).

 

Options:

 

Options on the command line apply only to the filenames which follow the option, and options at the end of the line apply to the preceding filename only. This allows you to specify different options for different groups of files, yet retains compatibility with the traditional DIR command when a single filename is specified.

 

/\Display directory names with a trailing \.

 

/1Single column display -- display the filename, size, date, and time; also displays the description on drives which do not support long filenames. This is the default. If /T is used the attributes are displayed instead of the description; if /C or /O:c is used the compression ratio is displayed instead of the description. This option is most useful if you wish to override a default /2, /4, or /W setting stored in an alias. On NTFS drives, single column displays will also show the target of symbolic links following the filename.

 

/2Two column display -- display just the name (on LFN drives), or display the filename, size, date, and time on other drives. See Multiple Column Displays above for more details.

 

/4Four column display -- display just the name (on LFN drives); or display the filename and size, in K (kilobytes) or M (megabytes) on other drives, with files between 1 and 9.9 megabytes in size displayed in tenths (i.e., "2.4M"). See Multiple Column Displays above for more details.

 

/:Display file stream names and sizes on NTFS volumes. When combined with the /B or /F options, the size is omitted.

 

When /: is used in conjunction with /B (Bare), the file name is displayed on the first line, then any streams, indented two spaces, on subsequent lines:

 

c:\test\myfile.dat

xyz:$DATA

abc:$DATA

 

When /: is used in conjunction with /F (Full path), the file name is displayed on the first line, then any streams are appended to the filename on subsequent lines:

 

c:\test\myfile.dat

c:\test\myfile.dat:xyz

c:\test\myfile.dat:abc

 

/A[:]Display only those files that have the specified attribute(s) set. See Attribute Switches for information on the attributes which can follow /A:.

 

You can specify /A:= to display a dialog to help you set individual attributes.

 

/BSuppress the header and summary lines, and display file or subdirectory names only, in a single column. This option is most useful when you want to redirect a list of names to a file or another program. If you use /B with /S, DIR will show the full path of each file (the same display as /F) instead of simply its name and extension. If you use /B with /X on an LFN drive, DIR will display the short name of each file instead of the long name. /B also sets /H.

 

/B1 will display relative paths when used with /S. (Normally, /B shows the full pathname for the file.)

 

/C Display per-file and total compression percentage on NTFS drives with compression enabled. /C only works in single-column mode; it is ignored if /2, /4, or /W is used.

 

/CD:Define a custom directory colorization string to use instead of the COLORDIR environment variable, or the ColorDir option in TCMD.INI.

 

/DTemporarily disable directory color coding. May be required when color-coded directories are used and DIR output is redirected to a character device like  a serial port (e.g., COM1). /D is not required when DIR output is redirected to a file.

 

/EDisplay filenames in upper case.

 

/FDisplay each filename with its drive letter and path in a single column, without other information. If you use /F with /X, the "short" version of the entire path is displayed.

 

/G[:n]Display the allocated disk space instead of the actual size of each file. You can optionally specify the disk cluster size to be used by /G. (DIR will normally query the system for the cluster size on the specified drive, but you can override with /G:n if you know that the returned info is incorrect, or if you want to find the size required if the specified files were moved to another device with a different cluster size.)

 

/HSuppress the display of the "." and ".." directories.

 

/HLShow the hard links for files and directories. /HL can only be used in single-column mode.

 

/I"text"Select filenames by matching text in their descriptions. The text can include wildcards and extended wildcards. The search text must be enclosed in double quotes, and must follow the /I immediately, with no intervening spaces. You can select all filenames that have a description with /I"[?]*", or all filenames that do not have a description with /I"[]".

 

The /I option may be used to select files even if descriptions are not displayed (for example, if /2 is used). However, /I will be ignored if /C or /O:c is used.

 

/JJustify (align) filename extensions and display them in the FAT format. If on an LFN drive, you must also specify the /X and /Z options.

 

/KSuppress the header (disk and directory name) display.

 

/LDisplay file and directory names in lower case.

 

/MSuppress the footer (file and byte count totals) display.

 

/NUse the long filename display format, even if the files are stored on a volume which does not support long filenames. See also /Z.

 

A /N with one of the following arguments has an alternate meaning:

 

dSkip hidden directories (when used with /S)
eDon't display an error message if no files match
fDon't display "bytes free" in the summary
hDon't display the header
jSkip junctions (when used with /S)
lDon't display the link name for symbolic links
m:nDisplay a maximum of n directory entries
sDon't display the summary.
vDon't display the volume information.
zSkip system directories (when used with /S)

 

/OSet the sorting order. You may use any combination of the sorting options below. If multiple options are used, the listing will be sorted with the first sort option as the primary key, the next as the secondary key, and so on:

 

nSort by filename and extension, unless e is explicitly included. This is the default.
-Reverse the sort order for the next sort key
aSort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension.
cSort by compression ratio (the least compressed file in the list will be displayed first). For single-column directory displays in the short filename format, the compression ratios will be used as the basis of the sort and will also be displayed. For wider displays (/2, /4, and /W) and displays in LFN format, the compression ratios will be used to determine the order but will not be displayed. For information on supported compression systems see /C above.
dSort by date and time (oldest first); also see /T:acw
eSort by extension
gGroup subdirectories first, then files
iSort by file description (ignored if /C or /O:c is also used)
oSort by owner
rReverse the sort order for all options
sSort by size
tSame as d
uUnsorted
xWhen combined with /S, sorts the results from all directories together and displays them in a single listing. (Unless you're also specifying /F, you probably won't get a comprehensible result.) Note that /O:x will turn off headers and footers.

 

/P[n]Wait for a key to be pressed after each screen page before continuing the display. Your options at the prompt are explained in detail under Page and File Prompts. The /P option has an optional argument n that specifies the number of seconds to wait for a keystroke before continuing.

 

/QDisplay the file or directory owner (NTFS and remote directories only).

 

/RForces long descriptions to be displayed on a single line, rather than wrapped onto two or more lines. Use /R when output is redirected to a character device, such as a serial port or the printer; or when you want descriptions truncated, rather than wrapped, in the on-screen display.

 

/SDisplay file information from the current directory and all of its accessible subdirectories. DIR will only display headers and summaries for those directories which contain files that match the filename(s), ranges, and attributes that you specify on the command line. DIR will display hidden subdirectories for compatibility with CMD.

 

If you specify a number after the /S, DIR will limit the subdirectory recursion to that number. For example, if you have a directory tree "\a\b\c\d\e", /S2 will only affect the "a", "b", and "c" directories.

 

If you specify a + followed by a number after the /S, DIR will not display any filenames until it gets to that depth in the subdirectory tree. For example, if you have a directory tree \a\b\c\d\e, /S+2 will not display the contents of \a or \a\b.

 

/TDisplay the filenames and attributes in the format RHSADENTPCOIJ, regardless of volume type:

 

R

Read-only

A

Archive

H

Hidden

D

Subdirectory

S

System

C

Compressed

E

Encrypted

O

Offline

N

Normal

I

Not content-indexed

T

Temporary

L

Junction or symbolic link

P

Sparse file



 

Attributes which are set are represented by their letter, unset attributes by the _ (underscore) character.

 

If you wish to add another option after /T, you must start the next option with a forward slash. If you don't, TCC-RT will interpret the /T as the /T:{acw} time display switch (see below) and the following character as a time selector. For example:

 

dir /tz                incorrect, will display an error

dir /t /z                correct

 

/T:a|c|w[u] Specify which of the date and time fields on a drive which supports long filenames should be displayed and used for sorting:

 

aLast access date and time (on VFAT volumes access time is always midnight).
cCreation date and time.
wLast modification (write) date and time (default).

 

If you append a u after the field, DIR will display the file time in UTC.

 

/UOnly display the number of files, the total file size, and the total amount of disk space used. Information on individual files is not displayed. /U1 will display summaries for each directory, but no total summary for each parent directory. /U2 displays the grand total only.

 

/VDisplay the filenames sorted vertically rather than horizontally (use with the /2, /4 or /W options).

 

/WDisplay filenames only, horizontally across the screen. On drives which do not support long filenames, or when used with /Z or /X, /W displays as many columns as it can fit into TCC-RT window, using 16 characters in each column. Otherwise (i.e., when long filenames are displayed) the number of columns depends on the width of the longest name in the listing. See Multiple Column Displays above for more details.

 

/XDisplay both the short name (8-character name plus 3-character extension) and the long name of each file on an LFN drive. In normal single-column output the short name is displayed first, followed by the long name. The short name column is left blank if the short name and long name are the same. On NTFS volumes this means case insensitive match, but on VFAT volumes this means case sensitive match (i.e., no lower case letters in the SFN). /X also selects short filenames in the /2, /4, /B, /W , and /Z displays, and short file and path names in the /F display.

 

/ZDisplay filenames on LFN drives in the old-style format, with the filename on the left and the description (when available) on the right. Long names will be truncated to 12 characters unless /X is also used. If the name is longer than 12 characters, it will be followed by a è "right arrow" symbol to show that one or more characters have been truncated. If a description file exists, /Z defaults to using the name of the . and .. directories as description for those entries