MS-DOS 6.22 Command Execution: Current Directory vs PATH
In MS-DOS 6.22, command resolution follows a rigid, built-in
hierarchy where internal commands take absolute precedence, followed
immediately by the current working directory, and finally the
directories specified in the PATH environment variable.
When a user types a command without specifying a path, the operating
system checks memory for internal commands, evaluates the active
directory for matching .COM, .EXE, and
.BAT files, and only queries the PATH variable
if no local match exists.
1. Internal Commands Take Immediate Priority
Before MS-DOS 6.22 looks at the disk—whether in the current directory
or within the PATH—it queries the command interpreter
(COMMAND.COM). If the entered command is an internal
command (such as DIR, COPY, CD,
or DEL), the interpreter executes it directly from memory.
An executable file in the current directory or PATH sharing
a name with an internal command (e.g., dir.exe) will be
ignored unless explicitly invoked using its file extension or relative
path.
2. The Current Working Directory
If the command is not internal, MS-DOS 6.22 checks the current
working directory. Unlike modern POSIX systems, which require an
explicit ./ prefix for security reasons, MS-DOS 6.22
automatically treats the current working directory as the first search
location for external programs.
Within the current directory, DOS resolves filename collisions using a fixed extension priority:
.COM.EXE.BAT
For example, if a folder contains both TEST.COM and
TEST.EXE, typing test executes
TEST.COM. If a match is found in the current directory, the
execution cycle completes, and MS-DOS 6.22 stops searching.
3. The PATH Environment Variable
MS-DOS 6.22 evaluates the PATH variable only when a
command is neither an internal command nor present in the current
directory. The search proceeds sequentially as follows:
- Left-to-Right Processing: DOS parses the
directories defined in
PATHstrictly in the order they are listed, separated by semicolons. - Extension Evaluation per Directory: For each
directory in the
PATH, DOS evaluates the same extension priority (.COM, then.EXE, then.BAT). It does not check all PATH directories for.COMfiles first; rather, it fully checks the first directory for all three extensions before moving to the next directory.
If the search exhausts all directories defined in the
PATH without locating a match, MS-DOS terminates execution
and returns the standard error message:
"Bad command or file name".
Practical Implications
Because the current directory always overrides the PATH,
users in MS-DOS 6.22 could unintentionally shadow system utilities.
Placing a malicious or alternative FORMAT.COM or
EDIT.COM file into a local working directory ensures that
running the command from that folder executes the local file rather than
the legitimate utility located in C:\DOS, highlighting the
critical role directory context plays in MS-DOS command resolution.