MS-DOS 6.22 DELTREE Multi-Level Directory Deletion
This article examines how the MS-DOS 6.22 external utility
DELTREE.EXE systematically processes and deletes
multi-level directory structures. Unlike standard internal DOS commands,
DELTREE performs a recursive, depth-first traversal of the
specified file system tree, automatically clears restrictive file
attributes, and removes both files and directory nodes from the bottom
up to comply with FAT12 and FAT16 file system constraints.
Invocation and Initialization
When a user executes DELTREE [drive:]path (optionally
using the /Y switch to suppress confirmation), MS-DOS loads
DELTREE.EXE into conventional memory. The utility verifies
the target path using MS-DOS Interrupt 21h system calls. If the path
points to a valid directory, DELTREE requests user
confirmation unless the /Y parameter was supplied. Upon
confirmation, the program shifts from basic path parsing to recursive
directory tree analysis.
Depth-First Traversal Mechanism
The FAT file architecture strictly prohibits the deletion of a
directory entry using DOS function 3Ah (Remove Directory /
RMDIR) if that directory contains any active file entries
or child directory pointers (other than the standard . and
.. entries). To resolve this restriction,
DELTREE must clear the contents of the lowest branch before
removing the branch itself.
To execute multi-level deletion:
DELTREEreads the specified directory table using INT 21h, Function4Eh(Find First File) and Function4Fh(Find Next File) with a wildcard attribute mask matching all entries.- When it encounters a subdirectory entry (identified by the
10hdirectory attribute),DELTREEpushes the current working context onto its internal recursion stack and descends into that child directory. - The utility repeats this descent down through every nested folder level until it reaches a leaf node—a directory containing files but no further subdirectories.
Attribute Overrides and File Deletion
Standard DOS file commands fail when encountering files marked with
System (04h), Hidden (02h), or Read-Only
(01h) attributes. DELTREE deliberately
circumvents this limitation to ensure complete removal without
administrative interruption:
- For every file identified within the current leaf directory,
DELTREEqueries its file attributes via INT 21h, Function4300h(Get File Attributes). - If any restrictive flags are present, it issues INT 21h, Function
4301h(Set File Attributes) with an attribute byte of00h(Normal), effectively clearing System, Hidden, and Read-Only protections. - Once normalized,
DELTREEinvokes INT 21h, Function41h(Delete File) to remove the file entry.
At the file system level, deleting a file marks the first byte of its
directory entry as E5h (indicating a deleted record) and
clears the corresponding cluster chain allocations within the File
Allocation Table (FAT), making the disk space available for future
allocation.
Bottom-Up Directory Removal
After all files inside the leaf directory are deleted, the directory
contains only its self-reference (.) and parent-reference
(..) entries. DELTREE then executes the
following sequence:
- The utility changes the active directory context up one level to the
parent directory using INT 21h, Function
3Bh(Change Current Directory). - It strips any special attributes assigned to the leaf directory
itself using INT 21h, Function
4301h. - It issues INT 21h, Function
3Ah(Remove Directory) targeting the empty leaf folder. This marks the directory's record in the parent folder's table withE5hand frees the data clusters that previously held the subdirectory's internal catalog. DELTREEunwinds one level of its internal recursion stack and resumes scanning the parent directory for any remaining files or sibling subdirectories.
Process Termination
The algorithm repeats this descend-clear-remove-ascend loop across
every branch of the target path. The process concludes only after every
nested level has been unlinked and the top-level directory specified in
the original command line has its contents emptied and its directory
entry removed. Control and an exit code of 0 are then
returned to COMMAND.COM.