Directory Commands of DOS

Certain DOS commands facilitate the creation or removal of directories so that you can organize the hard disk or a diskette. They also allow moving from one directory to another and viewing the list of files on a disk, under the root directory as well as other directories. These commands are the directory commands of DOS.

Displaying a List of Files on the Disk - the DIR Command

As stated earlier, there may be many files on a disk. If you wish to know which files you have on a particular diskette or on the hard disk, you can ask DOS to display the list of files on the disk.

For example, if you wish to view the list of files on the hard disk, the command would be:

C>DIR C: <Enter>

C: signifies the C drive. Pressing the <Enter> key indicates the end of the command.

A sample execution of the DIR command is shown in Figure.

For the time, ignore the significance of the first three lines. Notice that from the fourth line onwards, each line has 5 columns. The columns are:

  1. Primary name
  2. Extension


  3. Hence, columns 1 and 2 give the complete file name. For example, C0MMAND.COM is a file name where COMMAND is the primary name and COM is the extension.

  4. Size of each file in bytes. Recall that one byte stores one character
  5. Date on which the file was either created or modified last
  6. Time at which the file was either created or modified last

A Sample DIR Display

A Sample DIR Display

If you wish to see the list of files on the diskette, i.e. in the A drive, the command will be:

C>DIR A: <Enter>

In the list of files shown in Figure, PERSONAL is a directory. <DIR> signifies a directory. Therefore, the root directory of the C drive contains, apart from various files, a directory named PERSONAL.

Let us assume the directory PERSONAL contains a subdirectory called ADDRESS. To view the contents of the subdirectory ADDRESS, the command will be:

C>DIR C:\PERSONAL\ADDRESS <Enter>

where \PERSONAL is the path to the subdirectory Address

Thus, you can specify path to DOS along with the DIR command. If you wish to see whether a file named MK_APTS exists under the subdirectory ADDRESS, you can issue the command:

C>DIR C:\PERSONAL\ADDRESS\MK_APTS<Enter>

If the file does not exist there, DOS will indicate to you that the file has not been found.

If the currently active directory is the subdirectory ADDRESS, then the entire path need not be defined to DOS. The following command would be sufficient:

C>DIR MK_APTS <Enter>

You can see that the currently active drive need not be specified either. However, if you wish to view directory contents in a drive or a directory other than the active one, the complete path must be defined to DOS. Otherwise, an error message will be displayed.

More on the DIR Command

If you have a large number of files on a disk and you issue the DIR command, the file names will scroll off the screen and only the last few names will be visible. In such cases, the DIR command that can be used is:

C>DIR C:/P <Enter>

This command lists the contents of the disk page-wise. Once the screen is full of file names, the following message will appear and the scrolling will stop.

Press any key to continue...

When a key is pressed, the next screen of file names will be displayed.

An alternative command that can be used if one wishes to view all the file names at the same time is:

C>DIR C:/W <Enter>

A Sample DIR/W Listing

A Sample DIR/W Listing

The DIR/W command lists the contents of the disk width-wise, i.e. five file names per line (refer Figure)

As is evident from the screen in Figure, details like the number of bytes occupied by each file, the date and the time of creation of each file are not displayed with the file names when the contents are listed width-wise.