Directory Recursion Depth Limits in MS-DOS 6.22

In MS-DOS 6.22, the limits on directory recursion depth are determined by a combination of file system architecture, operating system buffer sizes, and utility-level constraints. While the underlying FAT16 file system does not define an explicit architectural ceiling for directory nesting, MS-DOS enforces strict path length limitations and internal memory restrictions that effectively cap how deep directory recursion can go.

FAT16 File System Structure

At the file system level, directories in FAT16 are simply special files containing arrays of 32-byte directory entries. Each directory points to its parent via the .. entry and to child subdirectories through regular cluster pointers. Because these pointers form a linked list across the File Allocation Table, the raw FAT16 specification has no theoretical depth limit other than running out of available disk clusters.

The Path Length Constraint (CDS Buffer)

The primary hard barrier to directory depth in MS-DOS 6.22 is the internal Current Directory Structure (CDS). MS-DOS allocates a fixed 67-byte buffer for tracking the fully qualified path of any drive:

  • Drive letter and colon (C:) = 2 bytes
  • Leading backslash (\) = 1 byte
  • Path string = up to 63 bytes
  • Null terminator (\0) = 1 byte
  • Total: 67 bytes

Because MS-DOS uses the 8.3 filename convention, the absolute shortest subdirectory name is a single character. Including the separating backslash, each nested directory level consumes at least 2 bytes (e.g., \A). Dividing the 63 available characters by 2 bytes per directory yields a practical absolute path limit of 31 to 32 levels of nesting under standard system calls.

Bypassing Depth Limits with SUBST

Users can circumvent the 67-character CDS path limitation by utilizing the SUBST command. By mapping a drive letter to a directory near the 67-character limit, the path length resets for that new drive:

SUBST E: C:\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O

From drive E:, an administrator can create another 31 levels of directories. Repeating this technique across available drive letters (up to Z:, configured via LASTDRIVE) allows directories to be nested well beyond 100 levels deep.

Stack and Utility Limitations

Even when the path length barrier is bypassed with SUBST, recursion depth is bounded by system memory and software design:

  • Internal Stacks: Deep directory recursion creates heavy stack usage. If a recursive process or disk interrupt exceeds the stack frame size defined in CONFIG.SYS (via the STACKS directive), the operating system triggers an Internal stack overflow - System halted error.
  • DOS Commands: Native tools such as TREE, DELTREE, DIR /S, and XCOPY /S allocate static memory buffers for path traversal. Even if the underlying file system can support deep structures via aliasing, these utilities will fail with "Path too long" or memory allocation errors when recursion exceeds their internal buffer limits.