Purpose: | Display information about files and subdirectories |
Format: | DIR [ranges] [options] [file...] |
ranges | one or more ranges |
options | one or more file selection or report format options |
file | The file, directory, or list of files or directories to display. |
1 column output |
Lower case |
||
2 column output |
suppress footer |
||
4 column output |
/N[desfhjlmvz] |
New format or disable options |
|
show streams |
Order |
||
Attribute select |
Pause |
||
Bare (name only) |
show owner |
||
show Compression |
disable wrap |
||
/CD:... |
COLORDIR string |
/Sn |
show Subdirectories to depth n |
Disable color coding |
show aTtributes |
||
upper case |
time type |
||
Full path |
show summary information |
||
/G[:n] |
allocated size |
Vertical sort |
|
Hide dots |
Wide |
||
Show hard links |
show short names |
||
/I"text" |
description range |
use FAT format |
|
Justify names |
Trailing \ for directory names |
||
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_dirs | The number of directories displayed |
%_dir_files | The number of files displayed |
%_dir_errors | The 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:
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.
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.
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.
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 |
SFN, size, date, time |
(Same as /X) |
(Same as /X) |
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_WIN32GUI | Windows x86 GUI app |
EXETYPE_WIN32CUI | Windows x86 console app |
EXETYPE_WIN64GUI | Windows x64 GUI app |
EXETYPE_WIN64CUI | Windows x64 console app |
EXETYPE_DOS | DOS (16-bit) app (obsolete) |
EXETYPE_POSIX | POSIX app (obsolete) |
EXETYPE_EFI | EFI 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.
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:
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.
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).
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 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.
/2 | Two 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. |
/: | 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.
/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. |
/F | Display 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. |
/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.
/J | Justify (align) filename extensions and display them in the FAT format. If on an LFN drive, you must also specify the /X and /Z options. |
/N | Use 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:
d | Skip hidden directories (when used with /S) |
e | Don't display an error message if no files match |
f | Don't display "bytes free" in the summary |
h | Don't display the header |
j | Skip junctions (when used with /S) |
l | Don't display the link name for symbolic links |
m:n | Display a maximum of n directory entries |
s | Don't display the summary. |
v | Don't display the volume information. |
z | Skip system directories (when used with /S) |
n | Sort by filename and extension, unless e is explicitly included. This is the default. |
- | Reverse the sort order for the next sort key |
a | Sort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension. |
c | Sort 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. |
d | Sort by date and time (oldest first); also see /T:acw |
e | Sort by extension |
g | Group subdirectories first, then files |
i | Sort by file description (ignored if /C or /O:c is also used) |
o | Sort by owner |
r | Reverse the sort order for all options |
s | Sort by size |
t | Same as d |
u | Unsorted |
x | When 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. |
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.
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: |
a | Last access date and time (on VFAT volumes access time is always midnight). |
c | Creation date and time. |
w | Last modification (write) date and time (default). |
If you append a u after the field, DIR will display the file time in UTC.
/V | Display the filenames sorted vertically rather than horizontally (use with the /2, /4 or /W options). |
/X | Display 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. |
/Z | Display 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 |