## Creating and Using Directories

It is possible to create a virtually unlimited number of levels of directories on a mass storage device using the makdir command. Directories are a special type of file (see the section called “Examining and Changing File Attributes”). They can be processed by the same I/O functions used to access regular files which makes directory-related processing fairly simple.

To demonstrate how directories work, assume that the disk in drive one (“d1”) has been freshly formatted so that it has a root directory only. The build command can be used to create a text file on “d1”. The build command will print out “?” as a prompt to indicate that it is waiting for a text line to be entered. It will place each line into the text file until an empty line with only a carriage return is entered, as shown below:

    OS9: build /d1/file1
    ? This is the first file that
    ? we created.
    ? [ENTER]

The dir command will now indicate the existence of the new file:

    OS9: dir /d1

       Directory of /d1  15:45:29
    file1

The list command can be used to display the text stored in the file:

    OS9: list /d1/file1

    This is the first file
    that we created.

The build command again is again used to create two more text files:

    OS9: build /d1/file2
    ? This is the second file
    ? that we created.
    ? [ENTER]

    OS9: build /d1/file3
    ? This is another file.
    ? [ENTER]

The dir command will now show three file names:

    OS9: dir /d1
       Directory of /D1  15:52:29
    file1           file2           file3

To make a new directory in this directory, the makdir command is used. The new directory will be called `NEWDIR`. Notice that throughout this manual directory names are always capitalized. This is not a requirement of OS-9 (see the section called “Pathlists: How Paths Are Named”). Rather, it is a practice popular with many OS-9 users because it allows easy identification of directory files at all times (assuming all other file names use lower-case letters).

    OS9: makdir /D1/NEWDIR

The directory file `NEWDIR` is now a file listed in D1's root directory:

    OS9: dir /D1

       Directory of /D1  16:04:31
    file1           file2           file3          NEWDIR

Now we will create a new file and put in the new directory, using the copy command to duplicate `file1`:

    OS9: copy /d1/file1 /d1/newdir/file1.copy

Observe that the second pathlist now has three names: the name of the root directory (“D1”), the name of the next lower directory (`NEWDIR`), then the actual file name (`file1.copy`). Here's what the directories look like now:

              D1 Root Directory
        +---------+--------+--------+
        !         !        !        !
      NEWDIR    file1    file2    file3
        !
        !
    file1.copy

The dir command can now show the files in the new directory:

    OS9: dir /D1/NEWDIR

       Directory of /D1/NEWDIR
    file1.copy

It is possible to use makdir to create additional new directories within `NEWDIR`, and so on, limited only by available disk space.