Organizing Your Hard Drive
By Ken Johnson, Chicago Computer Society
In last month's column we looked at files and file names. This
month we'll discuss how files are organized on a disk. Your
computer's hard disk can store many files, but finding and using
specific files (whether programs or data) can be difficult
without some sort of organization. Luckily DOS provides such
organization via a "subdirectory structure."
A physical disk is organized into a logical structure consisting
of a root directory (designated by a backslash "\") and various
named subdirectories which branch off the root. Graphically, the
directory structure looks like an upside-down tree. This tree-
structured directory system allows you to categorize your files,
placing like files into the same directory. Most users divide
their hard disk into several directories grouped around similar
types of applications or data:
C:\ (ROOT)
ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÁÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
123R23 WP51 UTIL DOS
ÚÄÄÄÄÄÄÙ ³ ³ ³
ÚÄÄÄÁÄÄÄÄ¿ ÚÄÄÄÁÄÄÄ¿ BIN NORTON
³ ³ ³ ³
BUDGET TAXES MEMOS ARTICLES
Thus, a directory structure grows like a tree. The root
directory contains all the main "branches" and each branch may
contain its own branches. The "leaves" of the tree are the
files:
C:\ (ROOT)
ÚÄ Ä Ä Ä Á Ä Ä
WP51
Ä Ä ÄÂÄÄÄÄÄÁ Ä Ä
MEMOS
³
MEMO5-4.92
MKTPLAN.FEB
2DO.LST
CLIENTS.LTR
The file MEMO5-4.92 is in the MEMOS subdirectory, which is in the
WP51 subdirectory, which is in the root directory of the C:
drive. The sequence of directories leading from the root to the
file is called the path.
As we discussed in last month's column, to find a file DOS needs
to know the path to the file, also that file's name and
extension. This is called the filespec. The filespec for the
file above is:
C:\WP51\MEMOS\MEMO5-4.92
where:
"C:\" indicates the root directory of the C: drive,
"WP51\MEMOS\" indicates the MEMOS subdirectory of the WP51
subdirectory,
and "MEMO5-4.92" is the file name and extension.
Organization of files into a logical subdirectory structure is
very important. Most application programs will create their own
subdirectories and install their files there. However, often you
will need to decide where to store your data files. A general
rule is to store your data in a separate subdirectory from the
program that created that data. For example, don't store your
WordPerfect documents with the WordPerfect programs.
The basic reason for storing data separate from programs is that
you care much more about the data than the programs. By keeping
the data separate, it is much easier to backup those important
files and more likely that you will do it. Data subdirectories
tend to be smaller, and often you can copy all the files onto a
single high density floppy using COPY or XCOPY. This can easily
be automated in a batch file, letting you make backup copies of
data files without having to really think about it.
The Root Directory
When you boot up your computer, you are logged into the root
directory of the hard drive C: (or the A: drive if you've started
with a DOS disk in the A: drive). The root directory doesn't
really have a name, rather the backslash character "\" stands for
the root directory. From the root, you use the CD (change
directory) to move to the subdirectories.
One sure sign of a disorganized hard drive is a root directory
full of files. The root directory need only contain a few
necessary files ("necessary" because DOS will look for them in
the root of the boot drive), including:
AUTOEXEC.BAT The AUTOmatically EXECute "startup" BATch file
containing commands to execute whenever the computer starts up.
CONFIG.SYS The file specifying CONFIGuration of your SYStem,
which loads device drivers and configures memory.
The root will also contain the two hidden DOS files (IBMBIO.COM &
IBMDOS.COM, or IO.SYS & MSDOS.SYS), and a hidden file containing
the volume label of the disk. Many people keep COMMAND.COM, the
command interpreter, in the root directory but this is not
required. The SHELL= statement in CONFIG.SYS can tell DOS where
to find COMMAND.COM if not in the root directory.
(The SHELL statement in CONFIG.SYS tells DOS the name of the
command interpreter (usually COMMAND.COM), its location, and the
size of the DOS environment. SHELL was discussed in the January
1992 and the September 1991 Hard-Copy Beginner's Columns.)
There is a limit on the number of files that can exist in the
root directory of any disk. The maximums are 112 files on a
Double Density, Double Sided 5¬ or 3« floppy disk, 224 files on a
high density 5¬ or 3« disk, and 512 files on most hard disks.
However, there are no limits on the number of files in a
subdirectory. Subdirectories are just files that keep track of
other files, and like any file can grow if there is disk space.
Subdirectories
Most of DOS' work is done in subdirectories. As mentioned above,
there is no limit on the number of files in a subdirectory, nor
is there a limit to the number of subdirectories you can have on
a hard disk. There is however a limit of the number of
subdirectory levels you can have, based on the length of the
subdirectory names. DOS limits a directory path to 63
characters, measured from the root to the bottom level. If you
use 8-character subdirectory names, this gives you a limit of
about seven levels. In practice, you won't have to worry about
this limitation since most users seldom have subdirectories more
than 3-4 levels deep.
The most important thing to remember about the directory
structure is that you can only be in one directory at a time.
This is called the "default directory," meaning that unless you
tell DOS otherwise, it will perform operations against files in
that directory. You can tell DOS to look in other directories by
using the PATH statement, and move to other subdirectories with
the CD command. We'll look at these commands below.
There are a couple of different ways to view subdirectories with
the DIR command. If you have DOS 5.0, you can use the /AD switch
to show only directories. Another method is to use "DIR *.",
that will show all files without extensions. Since most
subdirectories don't have extensions (though there is no reason
they can't) and most files do have extensions, this command will
usually show all the subdirectories one level down from where you
are.
For example, here is the output from "DIR /AD" on the root
directory of my D: drive:
Volume in drive D is STACVOL_DSK
Directory of D:\
123R23
12-01-91 2:45p
ARTICLES 04-12-92 6:54p
CSERVE 12-08-91 7:15p
EXCEL 07-05-91 6:17p
GMK 04-11-92 4:24p
JUNK 02-17-92 8:31p
TAP 03-21-92 11:50a
VB 07-13-91 10:45p
VISION 12-22-91 7:04p
VISIONR 12-22-91 7:25p
WP51 01-24-92 8:08p
WPC 03-29-92 5:47p
WPWIN 03-29-92 5:46p
WPWINDOC 03-29-92 5:46p
18 file(s) 0 bytes
18792448 bytes free
There are a couple of interesting items about these subdirectory
listings. Instead of showing a file size, subdirectories are
displayed with a "." This shows that these are directories,
not files without extensions. You can see from the byte listing
at the bottom of the display that subdirectory "files" have a
zero-byte length.
If you do a DIR command on a subdirectory, you'll see two special
entries at the beginning of the listing:
Volume in drive D is STACVOL_DSK
Directory of D:\ARTICLES
. 04-12-92 6:54p
.. 04-12-92 6:54p
MEMHELP BAK 19534 02-28-92 7:43p
DEFINEKY BAT 1159 03-04-91 6:17p
AUTOEXEC HLP 50345 08-20-91 8:44p
CACHE HLP 6243 12-29-91 11:06a
PROFILE KEJ 1361 01-26-92 7:48p
XNAME LIB 4485 05-23-92 3:02p
CACHE LOG 8687 12-22-91 7:54p
DOSBOOK MST 5538 04-14-92 9:36p
DELERASE OUT 13017 01-25-92 10:05a
The "." stands for the current directory, here D:\ARTICLES. The
double periods ".." stand for the parent directory, the directory
that is immediately above this one. In this example the parent
directory is the root directory (D:\). You can use this ".."
shorthand to quickly move up one level in the directory tree, as
we'll see below.
Now let's look at the commands used to manage subdirectories and
files.
MD (or MKDIR) -- create a new subdirectory
The MD Command (no one uses the long version, MKDIR) will create
a new subdirectory. The syntax is:
MD [d:][path]dirname
where "dirname" is the subdirectory name. If you simply enter
the name, the subdirectory will be created below the directory
that you are currently in. Alternatively, you can show exactly
where to create this directory by including drive and path
information. For example, suppose you are in the C:\DOS
subdirectory. The command
MD UTILITY
will create a C:\DOS\UTILITY subdirectory. With no path given,
the new directory is created relative to the default directory.
The command
MD \UTILITY
will create a C:\UTILITY directory directly off the root, no
matter which subdirectory you are in on the C: drive when you
issue the command.
RD (or RMDIR) -- delete a directory
To remove a subdirectory no longer needed, you can use the RD
command (again, no one uses the longer RMDIR version). The
syntax is:
RD [d:][path]dirname
where "dirname" is the directory to remove.
You cannot remove the root directory, or directory you are
currently in (the default directory). A directory must be empty,
containing no files or subdirectories, before it can be removed.
A hidden file may prevent you from removing a directory, since
the file cannot be deleted with DEL or ERASE. If you have DOS
5.0, you can use the ATTRIB command to turn off the Hidden
attribute, then delete the file normally. If you don't have DOS
5.0, you'll have to use a third party utility such as PCTools or
Norton Utilities to unhide and delete such files.
CD (or CHDIR) -- changes the default directory
The CD Change Directory command is used to move around the
directory tree. The syntax is:
CD [d:][path][dirname] [..] [\]
where "dirname" is the name of the directory that you want to
move to. If you simply give the directory name, then that
directory must be directly below the default directory.
Otherwise you will receive an "Invalid directory" message. You
can move to any directory on the drive by explicitly giving the
path and directory name.
Other uses of the CD command are:
CD \ Will move you back to the root directory.
CD .. Will move you up one level to the "parent"
directory of the directory you are currently in.
You can also use this as shorthand to move to
another directory with the same parent, as shown
below.
CD Will show the name of the current directory.
Let's look at some examples of the CD command. Let's say that
our disk is organized like so and that you are in the ARTICLES
subdirectory under the WP51 subdirectory:
C:\ (ROOT)
ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÁÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
123R23 WP51 UTIL DOS
³ ³ ³
ÚÄÄÄÄÁÄÄÄ¿ BIN NORTON
³ ³
MEMOS ARTICLES <-- you are here
³ ³
ÚÄÄÄÄÄÄÄÁ¿ ÚÄÄÁÄÄÄÄÄ¿
³ ³ ³ ³
1991 1992 CCS LAWMUG
CD .. will move you up to the parent, here the WP51
subdirectory (C:\WP51).
CD \ will move you back to the root directory (C:\).
CD CCS will move you down to the CCS subdirectory
(C:\WP51\ARTICLES\CCS). Since there is no path
specified, DOS looks for this subdirectory below
the current directory.
CD \UTIL\BIN will move you to the BIN subdirectory
(C:\UTIL\BIN). Since the directory name starts
with \, DOS begins looking for the UTIL
subdirectory off the root.
CD ..\MEMOS will move you to the MEMOS subdirectory
(C:\WP51\MEMOS). You use the ".." as shorthand
for the parent directory, here C:\WP51. It is a
quick way to move to another subdirectory with the
same parent.
CD will simply display the current directory
(C:\ARTICLES).
PROMPT -- change to DOS prompt to show the current subdirectory
In a complicated directory structure it is easy to get lost. You
can use the PROMPT command can end subdirectory confusion by
always displaying the name of the current directory. You've seen
the default DOS prompt often, the infamous "C>". The PROMPT
command can change "C>" to something a lot more informative.
The syntax of the command is:
PROMPT [prompt_text]
where "prompt_text" is any string of text or special characters.
These special characters will display system information as part
of your prompt:
$P the default directory
$T the current time (HH:MM:SS.xx)
$D the current date (MM-DD-YY)
$V the DOS version
$N the default drive
$_ Carriage Return (moves the cursor to next line)
$G the > character
$L the < character
$B the | character
$Q the = character
As you can see, the standard DOS prompt is $N$G, the default
drive and the ">" sign. If you enter the PROMPT command with
nothing after it, DOS resets the prompt to this default.
The prompt is usually set in your AUTOEXEC.BAT file, though it
can be reissued anytime from the DOS command line. Perhaps the
most common prompt setting is the current drive and directory:
PROMPT $P$G
DOS will display the current drive and current directory, with
the greater than sign. For example, if you are in the MEMOS
subdirectory of the WP51 directory on your C: drive, your prompt
will show:
C:\WP51\MEMOS>_
There is one minor problem when having DOS display the current
directory ($P). Each time you press Enter, DOS reads the disk to
find the directory for the prompt. If your default drive is a
floppy drive and you take the disk out (or you try to change to a
drive without a disk), DOS will try to read the empty drive and
you'll get an error message:
Not ready reading drive A:
Abort, Retry, Fail?_
At this point you can put a disk in and press R. Or you can
simply press F, in which case your prompt will become:
Current drive is no longer valid>_
Just change back to your hard drive and your prompt will
reappear.
By the way, there is an undocumented CONFIG.SYS setting in DOS
5.0 that will enter an "F" for you at any "Abort, Retry, Fail"
messages. You do this by adding a "/F" switch to the
SHELL=COMMAND.COM statement in CONFIG.SYS. Now anytime an
"Abort, Retry, Fail" message occurs, DOS will automatically
answer "Fail" and continue. Note that this switch is used with
COMMAND.COM as your command processor, and most likely does not
apply if you are using another processor (such as Norton's NDOS).
PATH -- where to search for files
The PATH command tells DOS the subdirectories to search when it
can't find the specified program in the current directory. DOS
will search this "path" of directories before it returns the "Bad
Command or Filename" error message. Some application programs
also use the path to find related files.
The path is specified by listing the directory to search,
separated by semicolons:
PATH dirname1;dirname2;dirname3; ....
A typical path might look like this:
PATH C:\;C:\DOS;C:\UTIL;C:\WINDOWS;C:\PCTOOLS;C:\DOS\NORTON
This path tells DOS to look in the following places (in the order
listed) for the file specified, if it can't be found in the
current directory:
C:\ (the root directory of the C: drive)
C:\DOS (the DOS subdirectory on the C: drive)
C:\UTIL (the UTIL subdirectory on the C: drive)
C:\WINDOWS (the WINDOWS subdirectory on the C: drive)
C:\PCTOOLS (the PCTOOLS subdirectory on the C: drive)
C:\DOS\NORTON (the NORTON subdirectory in the DOS
subdirectory on the C: drive)
The PATH is normally set in the AUTOEXEC.BAT file, and is limited
to 127 characters in length (the limit of the DOS command line).
If you have only a single hard drive, you can save a few
characters by eliminating the "C:" drive identifier. The path
above could be specified as:
PATH \;\DOS;\UTIL;\WINDOWS;\PCTOOLS;\DOS\NORTON
You'll want to put your important subdirectories on the path,
with the most "important" first, but don't include every
subdirectory. Long paths mean that DOS must search each of the
listed subdirectories, including every time you make a typo or
spelling mistake. Long paths can definitely slow you down,
particularly with a sluggish hard drive.
There are a couple of ways of viewing the current path. If you
simply enter "PATH" at the DOS prompt, DOS will display the path.
You can also enter the "SET" command to see the path, since DOS
keeps the path as an environmental variable. The SET command
will show all the environmental variables, including the PATH,
PROMPT, and COMSPEC. (See the January 1992 Hard-Copy Beginner's
Column for a discussion of the DOS Environment.)
Since the path is an environmental variable, it can be accessed
and manipulated in a batch file. This means you can dynamically
change the path as needed. For example, I use Grammatik 5 as a
grammar checker, but don't have it on my PATH statement. However
when I want to use Grammatik, the Grammatik subdirectory (\GMK)
must be on the path or the program can't run. So I've set up a
batch file to put the \GMK subdirectory on the path, run
Grammatik with WordPerfect, then remove \GMK from the path:
@echo off
set oldpath=%path%
path=d:\gmk;%path%
cd \wp51
gmkwp
path=%oldpath%
set oldpath=
Let's take a closer look at this batch program. The second line
creates a new environmental variable "oldpath" that contains the
original path (to use an environment variable in a batch file,
you surround it with percent signs). The next line creates a new
path, with the "D:\GMK" subdirectory as the first directory
listed; in essence, the original path is tacked on the end of
\GMK. The 4th and 5th lines change to the WordPerfect
subdirectory and run the Grammatik program. When Grammatik is
done, the 6th line sets the path back to the original path, which
was stored in the "oldpath" variable. The final line removes the
"oldpath" variable from the environment, freeing up the memory it
occupied.