MS-DOS 6.22 File Search Across Paths Using ATTRIB
MS-DOS 6.22 lacks a dedicated utility like modern Windows'
where command, but users frequently rely on the
ATTRIB command to locate files across nested directory
structures. By leveraging the /S recursive switch,
ATTRIB traverses entire directory trees to find matching
file patterns and displays their absolute paths. This article explains
the syntax, internal directory traversal mechanics, and practical
techniques for executing nested file searches using ATTRIB
in MS-DOS 6.22.
The Role of ATTRIB in File Searching
The primary purpose of ATTRIB.EXE is to view or alter
file attributes: Read-Only (R), Archive (A),
System (S), and Hidden (H). However, because
ATTRIB supports recursive directory parsing via the
/S flag and outputs the complete file path for every match,
it doubles as an effective search tool across deeply nested folder
structures.
Command Syntax for Searching
To search for files across nested directories, invoke
ATTRIB with a target file name or wildcard pattern,
accompanied by the /S switch:
ATTRIB [drive:][path][filename] /S
- Whole-Drive Search: To find a file anywhere on
drive
C:, start at the root directory:ATTRIB C:\FILENAME.EXT /S - Wildcard Searches: To find all files of a specific
type (such as batch files):
ATTRIB C:\*.BAT /S - Targeted Subdirectory Search: To limit the search
to a specific branch:
ATTRIB C:\DOS\*.SYS /S
Internal Traversal Mechanism
When ATTRIB executes with the /S switch,
MS-DOS 6.22 processes the search using a depth-first traversal
algorithm:
- Initial Query (INT 21h, Function 4Eh):
ATTRIBissues a "Find First File" system call using DOS Interrupt 21h, Function 4Eh, specifying the search pattern and matching file attributes. - Sequential Matches (INT 21h, Function 4Fh): It then calls "Find Next File" (Function 4Fh) iteratively until all matching files within the active directory are processed and printed to standard output.
- Directory Detection: Once the files in the current
directory are evaluated,
ATTRIBqueries the directory again to find child directory entries (marked by the0x10directory attribute bit in the FAT filesystem). - Recursion: For each discovered subdirectory
(excluding the
.and..navigational entries),ATTRIBsteps into the child directory and repeats the process. - Backtracking: Upon exhausting a directory branch, the program steps back up to the parent directory and moves to the next adjacent branch until the entire subtree has been scanned.
Displaying and Filtering Output
ATTRIB prints the attribute flags on the left, followed
by the full drive and directory path of the matched file:
A C:\AUTOEXEC.BAT
A R C:\DOS\ATTRIB.EXE
A HR C:\IO.SYS
Because output can scroll off the screen on large disks, pipe the
results into the MORE filter:
ATTRIB C:\*.EXE /S | MORE
Alternatively, redirect the search output to a plain text file for review in the MS-DOS Editor:
ATTRIB C:\*.COM /S > C:\RESULTS.TXT
Advantages Over DIR /S
While MS-DOS 6.22 also includes the DIR /S command for
recursive listings, ATTRIB /S offers distinct operational
differences:
- Compact Path Output:
ATTRIBoutputs each match on a single line containing the full path, making it cleaner for redirection and parsing by batch scripts. - Attribute Visibility:
ATTRIBinstantly indicates whether the matched files carry Hidden, System, or Read-Only attributes without requiring additional parameter flags.