Make your own free website on

MSM1 - Working with Directories in DOS

Working complete PC
Blank Diskette
Student Diskette, "New Boot A Ver 2.0+"
The student should become familiar with the DOS file system including:
File types,
The Root directory and subdirectories,
Drives and Partitions,
Copying files.
The student will become familiar with the nature of files and the file system and the logical perspective of drives, directories, and files. The student will be able to copy, copy files and create and navigate through directories of the file system of the PC.
  1. The instructor will issue each student a system unit, monitor, keyboard, and mouse that boots to DOS.

  2. Information must be stored on the system or the user would have to program the PC each time it is turned on. This was in fact the case on many microcomputers prior to the PC. Users would type in hundreds of lines of cryptic programming language code just to be able to play a simple game like "Pong." The IBM PC ended this era immediately by placing a large piece of software in a nonvolatile ROM on the motherboard that would test all components and then load an OS - Operating System - from a disk into RAM automatically. This programming that was emnedded into a ROM chip was the BIOS. And the operating system that it loaded was DOS. DOS, like all operating systems, was also a large set of programs that provided an enhanced environment for the user to be able to load and run software which is the end goal of the BIOS and the OS – to facilitate the development and execution of software.

  3. The software then must be stored on the disks in order to be retrieved and executed and the OS must be able to locate the software and the user must be able to ask for it by name, not disk sector numbers. The software and the OS itself are stored as files. The file is simply a large single piece of information that can span multiple disk storage sectors. It is the primary job of the OS to store files within the vast array of disk storage sectors and keep some form of database of information on the disk so that these files can be given human names that are then cross referenced against the raw storage sector numbers so that the files can be retrieved by the user at a later time. This cross reference of human given names to sector numbers and the organization of the entire array of disk sectors is called the file system.

  4. The highest organizational unit on the PC is a drive. Traditionally as defined in DOS, the first floppy drive is called "A:" All drives names are single letters followed by a colon. Drive B: has been reserved for use by a second floppy drive since they used to be very common. Drive C: has been reserved for use by the boot partition under normal circumstances. Partitions on hard drives are equal in status to the largest organizational unit in the PC: the physical drives. At the prompt, physical drives and partitions appear the same - as drive letters.

  5. No operating system accesses the PC’s hard drives directly. They could but it would make things cumbersome and the OS may not be aware of the existence of other OS’es in other partitions. It would read and write to those areas and destroy the other OS’es installation. Hard drives are divided up into partitions. Even if we only want one partition to span the entire drive it must still be set up that way. Even if we don’t plan on installing another partition the BIOS expects partitions as do all operating systems so the single partition must be created. Partitions only exist on hard drives not floppy disks. It is the partition that actually gets the drive letter and not the physical hard disk. So a single hard disk with no partitions would not be accessible from the DOS prompt at all and an HDD (Hard Disk Drive) with two partitions on it would be BOTH the C: drive and the D: drive.

  6. The utility that creates these partitions on the hard drive in DOS is called FDISK. This tool can create new partitions, set a partition active, delete partitions, and display the current state of the partitions. These in fact are the Main Menu choices within FDISK. We will return to FDISK in a future module.

  7. Inside of each drive there is a file system in place. Not only must the BIOS and OS recognize the drive (or in the case of hard drives, the partitions) these storage units must be set up to accommodate and organize files. The file system used by DOS (and the Windows families up to Windows ME) is called the FAT – File Allocation Table. There exist three types of FAT: FAT12, FAT16, FAT32. FAT12 uses entries that are 12 bits in size. FAT16 uses a table of 16 bit entries and FAT32 uses a table of 32 bit entries. DOS uses FAT12 on diskettes and FAT16 on hard disk partitions. Starting with Windows 95 OSR2 (a.k.a. "Windows 95B") and Windows 2000 (of the Windows NT Family of operating systems) hard disk partitions can be set up with the FAT32 file system.

  8. Each FAT entry is associated with a particular storage sector of the drive (or partition). This is how the OS will ultimately track down the files off of the surface of the disk. But this is nothing but a table of binary numbers. We name our files, how does DOS translate the name into these numbers? This is done with another special structure called the Root Directory.

  9. Each drive (or partition) must have a Root Directory even if it is empty. It is located at a specific location on the drive (or get the idea here) and it is a simple database that stores the file’s name, extension, creation/last modified time/date stamp, file attributes, length in bytes, and most importantly the starting FAT entry. So when you ask DOS for a file, it will look the human ASCII text name up in the Root Directory. When found it will check the starting FAT entry, this tells DOS which sector of the disk was used to store the first part of the file. It will check that actual entry in the FAT. If it has an End-Of-File marker there that means that only that sector is occupied by the file. If it has another valid entry number, then this means that sector contains the next piece of the file. DOS will read that sector into memory behind the first sector and go check that FAT entry’s number. It will continue retrieving sectors of the file into RAM and checking the next FAT entry until it runs into the End-Of-File marker in an entry. Then it knows it has read up the entire file and is done.

  10. No FAT file system based drive or partition is accessible if it does not have a File Allocation Table and a Root Directory. These structures are automatically created and initialized by the FORMAT command. Under normal circumstances there is no way to delete them. All files on a drive or partition lie somewhere under the Root directory. A file cannot be on the C: drive but outside of the Root Directory of the C: drive. This seems redundant but it is important to remember that the C: drive is considered a hard drive partition. DOS treats references to C: as references to the device or the partition information storage container. DOS treats the Root Directory as the repository or method of looking up and accessing all files within that drive or partition.

  11. So we perform SCANDISK C: on the partition of the hard drive looking for file system or surface integrity errors. But we list the contents of C:\ That backslash is the NAME of the Root Directory. On most standard 102-key keyboards it is the key above the [Enter] key – get used to it. As far as DOS is concerned if it has been installed on the first partition of the first hard drive in the PC the command interpreter’s real name is: C:\COMMAND.COM. And SCANDISK’s full name is: C:\DOS\SCANDISK.EXE.

  12. Do not confuse the file’s name with its execution. To execute a DOS command you type its name only. But if you wish to copy the program to another location then you must specify its extension as well. Think of it like talking to someone. As you talk to them you address them by their first name only. But if you want to tell somebody else about them you refer to them by their first and last name. When you execute SCANDISK you do so without the extension. When you want COMMAND.COM to copy SCANDISK.EXE to another location you must specify the full file name and extension.

  13. Place a blank floppy diskette in drive A: and format it bootable:

    C:\>format a: /s

    When the format is complete we will copy some files onto the floppy and get used to the command and how to use it.

  14. The first things that we will need on the floppy are the 2 essential DOS disk handling commands. Without these 2 commands it is NOT possible to prepare a hard drive for use. They are: FDISK.EXE and FORMAT.COM. FDISK as mentioned earlier creates the partitions that are required by the BIOS and DOS in order to recognize that there are storage sections called partitions on it. FORMAT then lays down the FAT and the Root Directories so that files can be stored and retrieved within these storage partitions on the hard drive.

  15. Let's see how to search the C: drive for a file. While in the Root Directory of any drive you can search for any file on it like this: DIR FILENAME.EXT /S The /S means search all subdirectories. Let’s find FDISK.EXE:

    C:\>dir fdisk.exe /s
     Volume in Drive C is DOS
     Volume Serial Number is 2221-04DC
    Directory of C:\DOS
    FDISK    EXE        29,336 05-31-94  6:22a
            1 file(s)         29,336 bytes
    Total files listed:
            1 file(s)         29,336 bytes
                       2,138,177,536 bytes free
  16. Above the file’s name you see the line “Directory of C:\DOS” that is where the file is within the file system. It is inside of the DOS subdirectory of the Root Directory of the C: drive. Now copy that file from that location to the bootable floppy diskette created earlier:

    C:\>copy fdisk.exe a:
    File not found – FDISK.EXE
            0 file(s) copied.
  17. COMMAND.COM assumes when you do not specify a full path name (just the file name) that the file is in the current directory. FDISK.EXE is not in the current directory. It is in the DOS subdirectory of the root. Therefore, we must tell COMMAND.COM to go into there and retrieve the file that we are referring to and then from there copy it to the floppy diskette:

    C:\>copy dos\fdisk.exe a:
            1 file(s) copied
  18. This is still an incomplete name for the file. The file’s complete name is actually: C:\DOS\FDISK.EXE but COMMAND.COM attaches the current directory to any name that does not start with a backslash "\". The current directory is displayed at the prompt so: "C:\" is attached to the front end of "dos\fdisk.exe" to create the full path name "C:\dos\fdisk.exe" when we execute the above command. This partial file name is called a relative reference and when a full path is specified it is called an absolute reference. Let's use an absolute reference to copy the other member of the 2 essential DOS disk handling commands to the floppy disk. Without these two files (FDISK.EXE is the first one) a new empty hard drive cannot function:

    C:\>copy c:\dos\ a:
            1 file(s) copied
  19. So FORMAT.COM is the other file that is necessary in order to get a new empty hard drive prepared for data storage. Now let's create a new empty directory in the root of the C: drive. The DOS command to do this is MKDIR or MD which is short for “Make Directory”. MD is an internal command. MD requires that you provide the name of the new directory to be created.

    C:\>md temp
  20. Notice that the MD command has no output to the screen. But there was no error message either. That means that whatever you asked DOS to do; it did it...very quietly. Let’s look and see if the new directory really exists.

     Volume in drive C is DOS        
     Volume Serial Number is 2221-0476
     Directory of C:\
    DOS          <DIR>         01-01-97  12:35a
    COMMAND  COM        54,645 05-31-94   6:22a
    WINA20   386         9,349 05-31-94   6:22a
    CONFIG   SYS            71 01-01-97  12:41a
    AUTOEXEC BAT            78 01-01-97  12:41a
    TEMP         <DIR>         03-06-03   3:16p
            6 file(s)         64,143 bytes
                       2,138,046,464 bytes free
  21. So the directory named "TEMP" does exist there at the bottom. And we know it is a directory because of the "<DIR>" entry next to it instead of a file size. Now change directory into the TEMP directory using the CD command:

    C:\>cd temp
  22. While DOS is standing within the TEMP directory, any command that does not specifically state otherwise will automatically be assumed to take effect within it or on the things within it. This is called the default action or target of the commands being issued and is a very important concept in DOS and in computers in general. Almost everything has its default: something assumed unless the user specifically states otherwise. While in the TEMP directory create three new subdirectories within it called "RED", "BLUE", "GREEN" and a "YELLOW" and then use DIR to check them. Now we will move into one of these new directories. The command to change position within the directory structure is CHDIR or CD which is short for "Change Directory" This is also an internal command and again you must specify which directory you would like to change into.

    C:\TEMP>md red
    C:\TEMP>md blue
    C:\TEMP>md green
    C:\TEMP>md yellow
    C:\TEMP>cd red
  23. If we think of each drive as a different house lot on the block, then the root directory represents the central room that one enters through the front door of the house. And each room inside is a separate subdirectory under the root directory.

  24. So moving into a subdirectory makes it the default when file names do not have full path names. While within the RED directory (room of the house) let’s move the memory manager to the floppy diskette.

    C:\TEMP\RED>copy dos\himem.sys a:
    File not found – HIMEM.SYS
            0 file(s) copied.
  25. Again, COMMAND.COM will add the current directory to the front of a relative reference so "C:\TEMP\RED" is added to what you typed "dos\himem.sys" to get "C:\TEMP\RED\dos\himem.sys" which, of course, is not correct. So use the full path name to copy the file (C:\DOS\HIMEM.SYS). Now let's create two new subdirectories inside of "RED".

    C:\TEMP\RED>md apple
    C:\TEMP\RED>md rose

    Now let’s move into "APPLE".

    C:\TEMP\RED>cd apple
  26. While standing here let's create a subdirectory of blue called "SEA". The problem is that "BLUE" is not underneath this directory it is parallel at best. Furthermore, we are going to need some way to view the directory tree structure before we get totally lost. Change directory back to the root directory. This can be done by naming the root in the command. Do not forget that, to DOS, the root directory’s name is "\".

    C:\TEMP\RED\APPLE>cd \
  27. Now let's take a look at the directory tree by using the TREE command.

  28. Run the TREE command and from this graphical display we can see that the directories "DOS" and "TEMP" are subdirectories of the root of the C: drive. We can see that "RED", "BLUE", "GREEN", and "YELLOW" are subdirectories of "TEMP." And "APPLE" and "ROSE" are subdirectories of "RED". Now let's return to the "APPLE" directory and create "SEA" under "BLUE".

    C:\>cd temp\red\apple
    C:\TEMP\RED\APPLE>md c:\temp\blue\sea
  29. Now check it and then create the directory "BANANA" under "YELLOW".

    C:\TEMP\RED\APPLE>dir c:\temp\blue
     Volume in drive C is DOS
     Volume Serial Number is 2221-0476
     Directory of C:\BLUE
    .            <DIR>         03-06-03   4:13p
    ..           <DIR>         03-06-03   4:13p
    SEA          <DIR>         03-06-03   4:24p
            3 file(s)              0 bytes
                       2,137,882,624 bytes free
    C:\TEMP\RED\APPLE>md c:\yellow\banana
  30. Now let's move from the current directory to the "ROSE" directory.

    C:\TEMP\RED\APPLE>cd ..
    C:\TEMP\RED>cd rose
  31. Have you noticed the "dot" and "dot dot" directories in the directories that we have been creating? These are road map entries for COMMAND.COM to read to be able to tell where it is within the file system at any time. The "dot" directory contains the physical address (FAT entry) to the current directory. The "dot dot" directory contains the physical address of the parent directory. In this case we are currently in the "ROSE" directory so the "dot" directory contains the FAT entry of the "ROSE" directory itself, and the "dot dot" directory contains the FAT entry to the directory "RED". "RED" also contains a "dot" entry which has the FAT entry to “RED” and the "dot dot" entry that contains the FAT entry to the TEMP directory. That directory has its dot and dot dot entries that point to itself and finally the root directory (its parent). From there DOS can crawl down into any directory and with the "dot" and "dot dot" entries find its way back to the root again. This is their purpose. This is also why the root does not have them. DOS knows exactly where the root directory is located on any drive. Now the command above said "cd .." So we asked COMMAND.COM to "change directory to the parent" or another way to say it is "move up one level" within the directory tree. Then we moved down into the directory "ROSE". Using "dot" or "dot dot" at the beginning of a path name reference automatically makes it a relative reference. Now let's move back to the "APPLE" directory using a relative reference.

    C:\TEMP\RED\ROSE>cd ..\apple

    Translated literally this command says "starting from where we are at within the tree, move up one level, then down into the APPLE directory."

  32. Now let's create the directory "SKY" within the "BLUE" directory using a relative reference.

    C:\TEMP\RED\APPLE>md ..\..\blue\sky
  33. The first "dot dot" in the relative reference refers to the parent of the current directory which is "RED." The second "dot dot" entry refers to the parent of that which is TEMP. The name "BLUE" means now turn down into that directory and the last name is to be created inside of "BLUE." No errors; so it did create it. Now let's move to the "BANANA" directory using a relative reference.

    C:\TEMP\RED\APPLE>cd ..\..\yellow\banana

    Now move back but use an absolute reference.

    C:\TEMP\YELLOW\BANANA>cd \temp\red\apple
  34. Notice that we still let DOS assume that this action was to occur on the current drive. It is very much an absolute reference because it begins with the backslash which indicates that we are talking about reckoning from the root down.

Copyright©2000-2004 Brian Robinson ALL RIGHTS RESERVED