MS-DOS 6.22 DIRCMD Variable Guide
In MS-DOS 6.22, the DIRCMD environment variable allows
users to customize the default behavior of the DIR command
by automatically applying specified command-line switches. Instead of
manually typing display and sorting parameters with every directory
listing, users define their preferences once using DIRCMD.
This article explains the role of DIRCMD, how to configure
it in system startup files, common switch combinations, and how to
temporarily override preset behaviors.
Purpose of the DIRCMD Variable
By default, the DIR command in MS-DOS 6.22 displays
files in the order they exist in the file allocation table, listing all
entries rapidly without pausing when the screen fills. The
DIRCMD environment variable is checked by
COMMAND.COM every time the DIR command is
executed. If defined, MS-DOS treats the assigned switches as the default
standard output for directory listings.
Common Switches Used with DIRCMD
Users can assign any valid DIR switch to
DIRCMD. The most frequently used options include:
- /P: Pauses the screen after each page of output until a key is pressed.
- /W: Displays files in a wide format, listing multiple columns across the screen.
- /L: Forces all file and directory names to display in lowercase.
- /B: Displays a bare format with no header, summary, or file size information.
- /O:[sortorder]: Controls the sorting order of the
directory.
N: Alphabetical by name.E: Alphabetical by extension.D: Chronological by date and time.S: By size, smallest first.G: Groups directories before files.- A minus sign (
-) preceding any sort key reverses the order (e.g.,/-Dsorts newest first).
How to Configure DIRCMD
To make DIRCMD persistent across system reboots, it
should be defined inside the C:\AUTOEXEC.BAT configuration
file using the SET command.
To open and edit the startup file:
EDIT C:\AUTOEXEC.BAT
Add the variable definition on its own line:
SET DIRCMD=/O:GEN /P /L
In this example, the listing will automatically group directories
first (G), sort entries by extension (E) then
name (N), pause at every full screen (/P), and
display file names in lowercase (/L).
To test or apply the variable during an active DOS session without
restarting, enter the SET command directly at the command
prompt:
SET DIRCMD=/O:G /P
To view the current value of the variable, type SET and
locate DIRCMD in the resulting list. To clear the variable
during an active session, type:
SET DIRCMD=
Overriding DIRCMD Settings
Preset parameters inside DIRCMD do not lock the user
into that specific view. When running a DIR query, you can
override any active switch by specifying an alternate switch or by
preceding the original switch with a hyphen (-).
- If
DIRCMDcontains/P, typingDIR /-Pdisplays the entire directory without pausing. - If
DIRCMDcontains/W, typingDIR /-Wdisplays the standard single-column detailed view. - If
DIRCMDsorts alphabetically by name (/O:N), typingDIR /O:Doverrides it to sort by date for that single execution.