Run Batch Files in Subdirectories in MS-DOS 6.22

MS-DOS 6.22 executes batch scripts located in subdirectories by resolving file paths through the command interpreter, COMMAND.COM. When executing these scripts, the operating system evaluates path specifications, maintains the caller's current working directory, and requires specific syntax—such as the CALL command—to preserve the execution flow between parent and child scripts. Understanding this process involves examining path resolution, working directory behavior, execution chaining, and environment search paths.

Path Resolution and Direct Invocation

When a command is entered at the command prompt or inside a batch file, COMMAND.COM parses the input to determine if it is an internal command, an executable (.COM or .EXE), or a batch script (.BAT).

If the command includes a path delimiter (such as \ or ..), MS-DOS bypasses its standard search sequence and looks directly at the specified directory. For example, entering:

C:\SCRIPTS\MAINT.BAT

or using a relative path:

SUBDIR\MAINT.BAT

prompts COMMAND.COM to open the specified folder, locate MAINT.BAT, and begin reading its instructions line by line.

Working Directory Behavior

Executing a batch file located inside a subdirectory does not change the active working directory. If a user is working in C:\GAMES and executes C:\UTILS\CLEANUP.BAT, the working directory remains C:\GAMES.

Consequently, any file operations inside CLEANUP.BAT that use relative paths (such as DEL *.TMP) will execute against C:\GAMES, not C:\UTILS. If the script requires working strictly within its own directory, it must explicitly navigate there using the CHDIR (or CD) command:

CD \UTILS

The Role of the CALL Command

In MS-DOS 6.22, invoking a batch file directly from inside another batch file causes an irreversible transfer of control known as "chaining." If PARENT.BAT calls SUBDIR\CHILD.BAT directly:

@ECHO OFF
SUBDIR\CHILD.BAT
ECHO This line will never execute.

The interpreter transfers control to CHILD.BAT and terminates execution when CHILD.BAT finishes, ignoring the remainder of PARENT.BAT.

To run a batch file located in a subdirectory and return to the original script, MS-DOS 6.22 provides the CALL command. Using CALL spawns a nested batch context:

@ECHO OFF
CALL SUBDIR\CHILD.BAT
ECHO Execution returns here after CHILD.BAT finishes.

Execution via the PATH Variable

If batch scripts in subdirectories need to be accessible from any location without specifying their relative or absolute paths, their parent directories can be registered in the system PATH variable.

When defined in AUTOEXEC.BAT or at the prompt:

PATH C:\DOS;C:\SCRIPTS;C:\UTILS

COMMAND.COM searches each directory in order if a command without a path is entered. If the user types MAINT, the interpreter checks the current working directory for MAINT.COM, MAINT.EXE, and MAINT.BAT. If not found, it traverses the PATH entries until it finds and executes the script from the appropriate subdirectory.