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 root and
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)...
|
|||
Root
|
Level 1 Subdirectory
|
|
Level 2 Subdirectory
|
C:\
|
WORDPROC
|
|
BOOK MEMOS LETTERS
|
|
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 Directory command.
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.
Make and Remove Subdirectories
If you are going to have subdirectories, there must be a way to make them. The syntax for
the make directory command is:
MD d:pathname\DIRNAME
You can make a subdirectory IN any directory FROM any
directory
so long as you give the
appropriate pathname. Usually, you will change to the directory you want the subdirectory to be in
and then issue a simple MD DIRNAME command. That way there is no mistake about what will
happen.
When you no longer need a directory you may
remove it from the disk. The first thing you have to do is empty it of files and move out of it. Only then will you be able to remove it. The
syntax for removing is:
RD d:pathname\DIRNAME
You cannot remove the root directory (it's the master for the disk and when it's the only directory you
would
have to
be in
it, and you can't remove a directory
you
are in).
Note: In DOS 6.0 the command DELTREE was introduced. DELTREE will both remove files from
a directory and remove that directory with
a single command.
Mysterious Dots
When you are in a subdirectory and issue the DIR command, you will see something like
this:
The dots indicate you are in a subdirectory. The single dot is the current directory and the
double dots
are the
parent
to the current
directory.
Thus
you could move to the parent of TUTORIAL (in the example above) by simply issuing the command CD
..
Used
with
care, the dots can
speed up subdirectory commands.
Tree
All directory paths and their relationships
are called a tree. If you don't remember the
various subdirectories (and optionally
the
files in them) DOS offers you a chance to see them with
the
TREE command:
TREE d:/f
This command lists all paths from the root on the disk. If you use the
/f
option, you will also
see all files in
each subdirectory.
(Only the
filenames are
shown, not
their size or creation date/time.)
For a permanent record, press Control-PrtScr before issuing the TREE command and again after.
Your printer will record all text scrolling past on the screen. (Or redirect to a file with TREE d:/f >
Filename.)
[Note: TREE has been removed under Windows.]
No comments:
Post a Comment