How MS-DOS 6.22 Handles Wildcards in CD
In MS-DOS 6.22, the internal change directory command
(cd or chdir) natively supports wildcards such
as * and ? to simplify folder navigation.
Instead of requiring an exact path name, the command processor evaluates
the wildcard pattern against the disk's directory table and
automatically switches to the very first matching directory it
encounters.
The Under-the-Hood Process
When a user issues a command like cd pro* or
cd d?r, COMMAND.COM does not perform
shell-expansion like modern Unix shells. Instead, it directly invokes
the DOS File Find system call via software interrupt
INT 21h, Function 4Eh (Find First Matching File).
During this call, MS-DOS 6.22 passes an attribute mask of
10h (the sub-directory attribute), along with the wildcard
string. The operating system parses the current directory's table within
the File Allocation Table (FAT) file system, scanning sequentially from
the beginning of the cluster list.
Directory Order vs. Alphabetical Order
Because COMMAND.COM only calls the "Find First" routine
and does not execute a "Find Next" (INT 21h, Function 4Fh),
it resolves to the first entry written to the disk table that matches
the criteria.
Crucially, MS-DOS file systems do not store directories
alphabetically; they are stored in the order they were created or where
deleted entry slots were reused. For example, if a directory named
PROJECTS was created after a directory named
PROGRAMS, cd pro* navigates to
PROGRAMS only if its directory record appears earlier on
the disk. If PROJECTS was created in an earlier vacated
directory slot, cd pro* navigates to PROJECTS
instead.
Attribute Filtering and Error Conditions
The system ensures that files matching the wildcard do not cause a false navigation attempt. When scanning the directory entries, the operating system checks the attribute byte of each match:
- Subdirectory Match: If the matched entry has the
directory bit set (
10h), the path buffer in DOS is updated, and the current working directory changes successfully. - File Match: If an entry matches the wildcard
pattern but lacks the directory attribute (such as a standard file named
PROJECT.TXT), the internal search skips it and continues checking subsequent entries until a genuine directory is found. - No Match: If the scan reaches the end of the
directory structure without finding a matching entry that carries the
directory attribute, MS-DOS halts the routine and displays the standard
error message:
Invalid directory.