DOS Lesson 10: Directory Commands

As we saw in the last lesson, DOS uses directories to organize the files on your disks. That means we need to use directory commands to create a structure to store our files, and to find the files we have stored there. The commands we need are relatively few:

(or MKDIR)
Create a new directory or subdirectory
(or RMDIR)
Remove (or delete) a directory or subdirectory
(or CHDIR)
Change from the current working directory to another directory
DELTREEErases a directory, including any files or subdirectories it may contain.
DIRList the contents of the current working directory

Because working with directories is central to what DOS does, all of these (except DELTREE) are Internal commands, contained within COMMAND.COM, and therefore loaded into RAM and ready for your use whenever you boot, including from a boot disk. You will note that the first three commands have two versions, a two-letter shorter name and a longer name. There is no real difference in use, so I will use the short form consistently in the presentation.


This command creates a new directory or subdirectory. (Actually, since the root is the main directory, all directories are subdirectories. So I will refer to subdirectories in all of the following.) Optional argument is the PATH, but if no PATH is included, the subdirectory will be created in the current working subdirectory


C:\>md letters

This would create the subdirectory C:\letters

With a path included, you can create a subdirectory anywhere.

C:\>md c:\letters\love

If you are in a different working subdirectory:

C:\letters\>md love

This would have the same effect as the previous example. Since we were already in the C:\letters subdirectory as our current working subdirectory,
we can leave out the path information since this is where we want the subdirectory created.

Limitations: The length of a PATH specification cannot exceed 63 characters, including backslashes.


This command removes a subdirectory. The subdirectory must be empty. If it contains files and/or subdirectories, you will get an error message. This also has an optional PATH argument, and has the same syntax as MD. Note
that you cannot remove the current working subdirectory. To do this, CD to
the parent subdirectory first, then remove the undesired subdirectory.

The RD command can sometimes be a little confusing because of the safeguards that DOS builds into the command. The idea that you cannot
delete a subdirectory that has contents, for instance, is a safety measure.
(DELTREE gets around this, but is a dangerous command for precisely that reason.) How can you tell if a subdirectory is empty? By using the DIR command to display its contents.


This command changes the current working subdirectory to another
subdirectory. Imagine a computer with the following directory structure:



Right now you are in the working subdirectory C:\letters\love\.
If you want to change to c:\letters\business\, you need to specify the path:

c:\letters\love\>cd c:\letters\business

If, however, you were in the working directory C:\letters\,
you would not need to use the path since the default is to go “downwards”:

c:\letters\> cd business

You can also use shortcuts:

cd \ will take you back to the root directory from wherever
you are.

cd .. will take you the parent subdirectory of the current working
subdirectory. So in the first example, you could also go in a two-step process:

c:\letters\love\>cd ..

c:\letters\> cd business

cd . will not do anything, but it is a valid command. The single
dot means the current working subdirectory, which is where you already are.<g>


This command was added later as an external command. It will delete an entire subdirectory “tree”, i.e. a subdirectory, plus all of the files it contains, plus all of the subdirectories it contains, and all of the files they contain, etc., all in one easy command. This makes it a dangerous command, because it can wipe out so much stuff so easily. It even ignores file attributes, so you can wipe out hidden, read-only, and system files without knowing it. You can even wipe out multiple trees by specifying them in the command:

C:\>deltree c:\letters c:\memos This would wipe out both of these subdirectories in one command.

This is one of those commands where you really ought to think twice before you use it. It has its place, definitely. I can remember how tedious it was to first go into each subdirectory, delete the individual files, check each subdirectory for contents, delete each subdirectory one at a time, then jump up one level and repeat the process. DELTREE is a great timesaver when you need it. But I would never use it for ordinary maintenance because one false move can do so much damage.


This command display the contents of a subdirectory, but it also can function like a search command, which many people do not realize. This is one of the most used commands in all of DOS, and learning to use it
properly is a great time saver.

DIR will display the contents of the current working subdirectory, or with an optional PATH argument it will display the contents of some other subdirectory. The real power of the DIR command comes with all of the optional switches available to you. You can display files in a variety of formats, for instance:

/pWill pause the screen when a full screen’s worth of information
has been displayed. You will see “Press any key to continue…”,
and press of a key will display one more screen. Great for searching those
long lists.
/wWill display the file names and subdirectory names in several columns
(i.e. wide), but without any other details.
/bBare format, displays file names only, without any other

In a future lesson, we will explore the intricacies of using the DIR command with all of the options available.

 Save as PDF