Tuesday, 8 January 2013

Subdirectory Introduction

As the name implies, a pathname is nothing more than a "path" that directs DOS to your
particular file.
You see, with DOS 2.x, IBM/Microsoft introduced multiple directories on a single disk. In
effect, this lets you sort your files into groups and place each related group into its own directory.
This means you don't have to search an entire disk to find one file.
A lower-level directory is called a subdirectory (what else?)
Seriously, consider a disk. To this point you have learned that each file on that disk is represented as
an entry in the directory, put there so both you and DOS can find the file on disk.
If, instead of data, you created a file that pointed to other  files on the disk, you will have
built what amounts to a subdirectory.
DOS manipulates files in subdirectories through several directory commands and what is
called a pathname.
In this section we'll look at the DOS commands for manipulating subdirectories and how we
can set an environment variable (PATH) to allow DOS to find programs.
The DOS directory structure can be thought of as a tree, with the master disk directory being
called the  rootand subdirectories thought of as branches. The root is the hard disk's master
directory. It may contain up to 512 entries. Subdirectories may contain any number of entries (until  the disk is full). A floppy root directory may contain 112 or 224 entries. A typical tree might look
like...



In the example there are five files and two subdirectories in the root. Each of the
subdirectories has similar contents. SubDir1, for example, has three files and one subdirectory in it.
This structure can be extended until the disk is completely full, subject only to the constraint of 63
characters for the pathname that you will use to find a particular file.
The rules for a subdirectory name are just like that for filenames (eight characters followed
by a period and three character extension).
They show up in a directory listing with the designator <DIR> behind them.
Let's see now how to build a pathname.



Pathnames 


Assume the subdirectory structure (only directories are shown, not files)...



This series of subdirectories was set up to categorize  various files developed by a word
processor. Let's move in the structure:
•  \WORDPROC\LETTERS Would be the pathname from the root to subdirectory LETTERS.
•  \WORDPROC Is the pathname from root to WORDPROC.
Note that each subdirectory in the path is separated by a backslash (\). The single backslash at
the beginning of the pathname indicates the root. All pathnames must originate in either the current
directory or root.
A test -- What is the pathname from the root to the subdirectories listed below?
•  Subdirectory LETTERS
•  Subdirectory BOOK
•  Subdirectory WORDPROC
Answers...
•  \WORDPROC\LETTERS
•  \WORDPROC\BOOK
•  \WORDPROC
When DOS is booted, the root directory is automatically selected. To type a file named
MYMEMO.TXT in subdirectory MEMOS the command would be:
C:\> TYPE \WORDPROC\MEMOS\MYMEMO.TXT
\WORDPROC\MEMOS\ is the pathname that DOS would use to find the file MYMEMO.TXT and
then show it on the screen.
If you've got work to do with files in the MEMOS subdirectory, typing the complete
pathname all the time would be inefficient. Therefore, DOS gives you a method of making DOS
recognize the MEMOS directory as the default: the Change Directorycommand.
To change to the MEMOS subdirectory from the root the command would be:
C:\> CD\WORDPROC\MEMOS
If set properly (see just below) the prompt might also change to reflect the change directory
(C:\WORDPROC\MEMOS>, and a DIR command would now show the contents  of the MEMOS
subdirectory instead of the root and DOS would look for all command files in that subdirectory
instead of the root.
An easy way to keep track of where you are in the directory tree is to use the  PROMPT
command to set a prompt that shows the current directory along with the current drive. You can
easily do this by adding the line:
PROMPT $P$G
to your AUTOEXEC.BAT file.

No comments:

Post a Comment