3.4.1 Directory Management

A program can use Create Directory (Interrupt 21h Function 39h) to add new directories within the current directory, or within other directories if the full path required to specify the new directory does not exceed 64 characters. Unlike the root directory, the new directory is limited only by the amount of space available on the medium, not by a fixed number of entries. MS-DOS initially allocates only a single cluster for the directory, allocating additional clusters only when they are needed.

Every directory except the root directory has two entries when it is created. The first entry specifies the directory itself, and the second entry specifies its parent directory—the directory that contains it. These entries use the special directory names . (an ASCII period) and .. (two ASCII periods), respectively. Programs can use these “names” to form partial paths.

Each directory has attributes that specify the type of access programs have to it. Programs set these attributes by using Set File Attributes (Interrupt 21h Function 4301h). The most common attributes, hidden and system, are often set to prevent users from displaying the directory with the dir command. A directory can also be made read-only, although this attribute does not prevent the deletion of the directory or its files. A program can retrieve a directory's attributes by using Get File Attributes (Interrupt 21h Function 4300h)

A program can rename a directory by using Rename File (Interrupt 21h Function 56h), but the new name must not cause the full path for the directory to exceed 64 characters. The program must check the path length, since MS-DOS does not.

A program deletes a directory by using Remove Directory (Interrupt 21h Function 3Ah). A directory cannot be deleted unless it is empty—that is, contains no files or other directories.