Chapter 5. Understanding Files and Directories

Introducing the DOS File System

Two primary roles of a disk operating system are storing and retrieving data. This chapter introduces you to the fundamental ways in which DOS handles these roles. To provide data storage and retrieval, the operating system must provide a common method for file storage and retrieval so that any software package can access information easily and quickly. It is also important that DOS provide these services without your having to know the internal details of how the disk works and why.

DOS generally insulates you from the technical details involved in storing and retrieving data on your computer. You must, however, prepare disks by formatting them, and you might occasionally have to repair them. In this chapter, you learn information about the most basic part of DOS—the file and directory system. After you've mastered this information, you will have a firm footing for understanding DOS completely.

Ask almost any non–computer user what a file is, and he or she almost invariably describes a collection of papers wrapped in a manila folder. Such files are typically stored in file cabinets.

On a computer, a file system is an organized collection of files that has a direct parallel to the old, familiar file cabinet. The hard disk and floppy disks you use to store data electronically use many of the same conventions. Each file on a disk has a unique name, just as each file folder in a file cabinet is labeled for identification. Files are arranged on your disks in directories (discussed later in this chapter) to make them easier to find, just as sections in a file cabinet are organized into group file folders that have a common purpose.

Understanding Files

A file is a variable-length collection of related information that is referenced by a name. Just as a file folder can be filled with various papers that contain information in the form of writing, an electronic file can contain various pieces of related information wrapped up in an electronic file folder referenced by the file's name.

Files written to disk can serve many purposes. A word processor file might hold all the sentences in a letter or book chapter. A database file might contain the names and addresses of all the members of a club or all the invoices for a store. Just as a good secretary uses color-coded labels and different markings on file folders to indicate the type of information in a file, DOS filenames most often indicate what kind of information they hold.

Often the way data is written in a file depends on the software that creates it. You can type the same letter, using all the same words and punctuation, using Microsoft Word and WordPerfect. When printed, the letters are identical, yet the format of the files created by these two programs is very different. You can, with a little work, use Microsoft Excel or Lotus 1-2-3 to store the same letter in yet another file format.

Although many programs recognize one another's file formats and convert them for you, DOS cares little about the format of a file's content. DOS doesn't bother trying to decipher the contents of a file. Its job is to wrap the information in a file folder (the file's name) and put it where you can find it later. Your job is to know what the file contains and which program you need to use to access correctly the data contained in the file.

In a computer setting, a file can contain data (information), programs (instructions that guide computer tasks), or both. A file can exist on a disk, on magnetic tape, on CD-ROMs, or even in a computer's memory. Files are made up of elements of data or programs. The individual elements can be stored as patterns of holes in a paper tape, as patterns of magnetic fields on the surface of a disk, and in many other ways.

Fortunately, unless you write programs for a living, you usually can ignore the technical aspects of how a file is stored. After all, you don't have to know how a fuel injector works to drive a fuel-injected car.

Physical storage techniques for files vary greatly, but on PCs a few file storage methods dominate. On PCs, floppy disks are used primarily for distributing files to other computers. Hard disks provide long-term and working storage. CD-ROMs often are used for storing files that do not need to be edited or altered, and tape drives and floppy disks are used to make backup copies of files for safekeeping.

Regardless of the actual media (floppy, hard disk, tape, and so on), DOS uses filenames to identify files. As you might remember from an earlier chapter, a full filename consists of one to eight characters followed by a period (.) and up to three characters called the extension. The period and extension are optional but are used almost universally.

The name portion of a filename (before the period) usually provides a mental picture or description of the contents of the file. Extensions, on the other hand, traditionally describe the type of file—its format.

If you're using a word processing application to write a memo, you might use as the name portion of a filename the name (or a close approximation) of the person who will receive the memo. You then can use the extension .MEM to indicate that the file is a memo. You can call a memo to Mr. Fleenor, for example, FLEENOR.MEM. Similarly, you can use the extension .DOC for office-policy document files. A monthly policy statement for January can be named JAN.DOC.

DOS enables you to use a wide variety of filenames. You are free to develop your own file-naming conventions, provided that you stay within the character limits imposed by DOS and the requirements of the software you use to create the file. Although most software packages are lenient in the filenames they can use, many programs require a file to have a specific extension before they recognize the file as one of their own

Understanding Filenames

DOS ensures that every one of your files has a name. In fact, DOS does not provide a way to put file data on a disk without a filename. When a file is created, either by your software or a DOS file service routine, information about the physical location of the file is stored in a File Allocation Table (FAT), which is similar to a book's table of contents. DOS places the name of each file and its attributes in a special structure called a directory, which you can think of as the chapter headings of a book. Using this analogy, you can think of files as the pages in each chapter.

For now, however, you need only concern yourself with the names of files. You learn more about the other parts of the DOS file system later in this chapter. Keep in mind that a directory is a special structure used to store filenames and files. Later in this chapter, you learn more information about the directory.

Creating Filenames

The characters you see on your computer screen are the ASCII code representations of bytes of data. One character is stored in one byte. In a disk directory, each slot where a filename can be stored reserves a space 11 bytes long (8 for the first part of the filename plus 3 for the extension). DOS accepts for filenames most characters that you use for “everyday” names. You can use the uppercase and lowercase letters A through Z; DOS automatically stores letters in uppercase in a directory entry. You also can use the numeric characters 0 through 9 and many punctuation characters not used as separators in the file system.

Following are the rules for creating legal filenames:

  • Each filename on a disk must be unique.

  • Filenames, even though they are not always expressed that way, include the drive letter and directory path of the file. In practical terms, this naming convention means that each file in a directory must have a unique name because the difference in directory names adds to a filename's uniqueness.

  • A filename consists of the following items:

    • A name of one to eight characters

    • An optional extension of one to three characters

    • A period between the name and the extension (if an extension is used)

  • The following characters are allowed in a filename:

    • The letters A through Z (lowercase letters are transformed into uppercase automatically)

    • The numerals 0 through 9

    • The following special characters and punctuation marks:

      $ # & @ ! ( ) - { } '_ ~ ^ '
      
  • DOS reserves certain ASCII codes for other uses and does not let them be a part of the filename. The following characters are not allowed in a filename:

    • Any control character (ASCII codes used as commands)

    • The space character

    • The following special characters and punctuation symbols:

      = / [ ] " : ; , ? * < > |

To understand why DOS disallows the use of some characters in filenames, you must look below the surface of DOS. Certain characters are not allowed because DOS does not pass those characters from the keyboard to the command or external command program that controls a file's name. You cannot, for example, use the Ctrl+G (^G) character in a filename because Ctrl+G tells an input device to sound the computer's bell or beep signal. DOS does not accept the Escape character, produced by the Esc key, as part of a filename because DOS interprets the Esc key as your request to cancel the command line and start again.

Another example of an unacceptable character is Ctrl+S (^S), which DOS and other operating systems use to stop the flow of characters from the input device to the output device. Ctrl+S stops screen scrolling, for example. If you press Ctrl+S while entering a filename, DOS assumes that you are entering an input-stopping character, not part of a filename.

You cannot use in a filename any characters that COMMAND.COM and external command programs use to divide the parameters and switches from the command in a command line. Because DOS must parse (distinguish the various components of) the command line, certain characters are seen as delimiters of parameters or as parts of a parameter. The backslash character (), for example, separates directory names in a path specifier. DOS always reads a backslash in a command line as part of a path.

Avoiding Reserved Names

One of the ways in which DOS is able to control so many different types of devices is by using a logical device. It is important to understand that each of these devices has a name that is reserved and cannot be used for other purposes.

In theory, DOS treats all the input and output devices it controls as if they were made out of software. Such devices include almost everything you think of as belonging to a computer system—disks, printers, keyboards, screens, and modems.

The PC manufacturers are responsible for accepting and generating data in a fashion that conforms to DOS standards. The actual control over the actions of a device (print heads, disk drive motors and heads, and so on) is left to programming contained on ROM chips incorporated into the devices. Thus, DOS needs to know only that a printer exists and that the printer is connected to the system in a specific way, normally via a parallel or serial port.

To you, a parallel port is a hardware connector where you plug in a cable. To DOS, the parallel port is simply an address in memory where it sends and receives data. Each of these addresses is called a logical device and is given a name. By default, DOS expects to see a printer connected to the first parallel port, which it calls LPT1.

The first available disk is A:. By convention, B: is reserved for the second floppy disk, and C: is reserved for the first hard disk volume. The keyboard and video card are combined to create a logical device named CON:.

Notice that all these logical device names end with the colon (:). The colon signifies that something is a DOS logical device. In some contexts, however, the colon is omitted, as in this example:

COPY CON SUMFILE.TXT

This variation of the COPY command tells DOS to take input from the console (CON:) and save it to the currently logged drive and directory as a file having the name SUMFILE.TXT.

What does all this talk of logical devices have to do with filenames? Simply, DOS's internal routines treat logical devices like files in many ways. That's why when you try to name a file with a name for a logical device, DOS gets confused and weird things can happen, such as losing data or sending a file to a printer.

For this reason, DOS reserves names for its logical devices. DOS can treat some of these logical PC devices in a high-level way by accepting their names as input or output parameters in a command line, as in the preceding example. Before it uses the filename parameters in a command line to look for a file, DOS checks to see whether the filename is a device name. Table 5.1 lists the major logical DOS input and output device names and their purposes.

Table 5.1. DOS Device Names

Device Name Purpose
COMx or AUX Identifies a serial communication port (x can be the number 1, 2, 3, or 4).
LPTx or PRN Identifies a parallel printer port (x can be the number 1, 2, 3, or 4).
CON Identifies the screen and keyboard.
NUL Identifies the “do nothing” device, also called a bit bucket. Output sent to NUL is not displayed, stored, or acted on in any way.
CLOCK$ Provides date and time services.

Never attempt to write a disk file with a name that is the same as one of the device names listed in Table 5.1. DOS intercepts the device name, even if you add an extension, and tries to use the device—not the file you intend—to complete the command. Use a device name only as a device parameter in a command.

Observing File-Naming Conventions

A convention is an informal rule that is not explicitly enforced. DOS filenames often follow certain conventions. Although you can use any filename that follows DOS's character and device-name rules, observe DOS file-naming conventions whenever possible. You can, for example, name a memo file and give it a BAT extension, but this extension has a special meaning to DOS because all batch files have the extension BAT. As long as you do not try to execute the memo as a batch file, DOS is happy. If you try to execute the memo file, however, DOS sees the BAT extension and tries to execute it. Of course, the memo cannot be executed because it probably isn't made up of legal DOS commands.

You can name an EXE file with a COM extension. Although both files are executable, they have internal differences. DOS does not take the extension's name to mean that the file is indeed an EXE or COM file; DOS inspects a key part of the file before deciding how to load and execute the program file. If you name a spreadsheet file as an EXE or COM file, for example, DOS is not fooled into executing the nonprogram file. In all likelihood, your system simply will lock up, and you will have to perform a warm boot to begin again.

Many software manufacturers use certain extensions for special file formats created by their applications. To avoid confusion about the contents of a file, avoid using those extensions. Table 5.2 lists some conventional filename extensions and their meanings. Multiple programs can use the same extensions in their file-naming conventions.

Table 5.2. Common Filename Extensions

Extension Common Use
ARC Archive (compressed file)
ASC ASCII text file
ASM Assembler source file
BAK Backup file
BAS BASIC program file
BAT DOS batch file
BGI Borland Graphics Interface file (Quattro, Paradox)
BIN Binary program file
BMP Windows bitmap file
C C source file
CPP C++ source file
CBL COBOL source file
CFG Program configuration information
CHP Chapter file (Ventura Publisher)
CHR Character file (Quattro, Paradox)
CNF Program configuration information
COM Program file
CPI Code page information file (DOS)
DAT Data file
DB Database file (Paradox)
DBF Database file (dBASE)
DCT Dictionary file
DEV Program device driver file
DIF Data Interchange Format file
DIR A program data file used as a directory
DLL Windows dynamic link library
DOC Document file (used by many word processors)
DOT Word for Windows template file
DRV Program device driver file
DTA Data file
EPS Encapsulated PostScript file
EXE Executable program file
FNT Font file
GIF Graphics Interchange Format file (CompuServe)
GRP Windows Program Group
H A header file for a C program
HLP Help file
IDX Index file (Q&A)
IMG GEM image (graphics) file
INF Information file
INI Initialization files (Windows and other programs)
LET Letter
LHA Compressed file (LHARC)
LIB Program library file
LOG File logging actions
LST Listing of a program (in a file)
MAK A programmer's make file
MAP Linker map file
MSG Program message file
NDX Index file (dBASE)
OBJ Intermediate object code (program) file
OLD Backup file
OVL Program overlay file
OVR Program overlay file
PAK Packed (archive) file
PAS Pascal source file
PCX Picture file for PC Paintbrush
PIF Program Information File (TopView/Windows)
PM4 PageMaker 4 data file
PM5 PageMaker 5 data file
PRN Program listing for printing
PRO Profile (configuration file)
PS PostScript program file
RFT Revisable Form Text (Document Content Architecture)
RPT A report file
RTF Rich Text Format, a Microsoft document exchange format
SAM Ami Pro document
SAV Backup file
STY Style sheet (Ventura Publisher, Microsoft Word)
SYS System or device driver file
TIF Picture file in Tagged Image File Format (TIFF)
TMP Temporary file
TST Test file
TXT Text file
WK1 Worksheet file (Lotus 1-2-3 Release 2)
WK2 Quattro Pro 5.0 spreadsheet file
WK3 Worksheet file (Lotus 1-2-3 Release 3)
WKQ Quattro spreadsheet file
WKS Worksheet file (Lotus 1-2-3, Releases 1 and 1A)
WQ1 Quattro Pro spreadsheet file
XLM Excel macro file
XLS Excel spreadsheet file
ZIP Compressed file (PKZIP)

Understanding File Attributes

As you will learn later in this chapter, DOS tracks each file on a disk through a directory entry. This entry maintains critical information about the file and where it is stored on disk. One of the pieces of information maintained in the directory entry is called the file attribute field. This one-byte field stores a number of characteristics about each file but is not displayed in a normal directory listing. Each characteristic stored in the file attribute field is called a file attribute, and each file can have more than one file attribute. Each file attribute is represented in the attribute byte by a single bit, often called an attribute bit. Table 5.3 lists the attributes and their purposes in DOS. You can view and modify most attribute bits by using the ATTRIB command; DOS manages some attribute bits directly.

Table 5.3. File Attributes and Their Meanings

Attribute Bit Meaning
Archive When DOS writes to a file, it sets the Archive attribute on. Some DOS commands such as MSBACKUP and XCOPY remove this attribute from files. Files having the Archive attribute have been altered or created since the last time they were archived.
Hidden This file is bypassed by most DOS file-managementcommands and does not appear in a directory listing. Hidden files, however, are listed by the DOS Shell in the file list area.
Read-only This file can be accessed for information but cannot be erased or modified. (Note that you can erase a read-only file by using the DOS Shell.)
Subdirectory This attribute identifies the entry as a directory rather than a standard file.
System This file is a DOS system file.
Volume Label This entry is the volume label for a disk. The entry does not identify an actual file.

The Archive attribute works with DOS file-management commands to determine which files the commands process. The MSBACKUP command resets the Archive attribute of any file it copies to disk. As you work with the files on your disk, each file on which DOS performs a write operation gets flagged with the Archive attribute, which signals that the file has changed since it was last archived. If you have a recent full-disk backup, you can create a backup of only the files that have changed since the last backup by telling MSBACKUP that you want to copy only files having the Archive attribute.

A file entry with the Hidden attribute turned on is “invisible” determineto most DOS file-management commands. Hidden files have filenames and extensions like normal user files but are not processed by the DIR and COPY commands. The two DOS system files on the boot disk are examples, as are the files that manage a DoubleSpace drive.

You can detect the presence of hidden files by using the ATTRIB or CHKDSK command. Using ATTRIB, you also can list hidden files. CHKDSK merely indicates the number of hidden files on the disk.

The Subdirectory attribute indicates to DOS that the entry is not intended for a user file but for an additional directory called a subdirectory. When it carries out file-management commands, DOS knows to bypass a file with the Subdirectory attribute turned on.

The System attribute indicates that a file is an operating system file. The two DOS system files have this attribute in addition to the Hidden attribute. You need not worry about the System attribute; it does not affect your DOS work.

The Volume Label attribute indicates that the directory entry involved is to be used as the name of the volume, not as a filename. DOS then combines the filename and extension fields to provide an 11-character volume label for the disk. Only a Volume Label entry can have this attribute set (turned on).

The Archive, Hidden, Read-only, and System attributes are the only attributes you can change directly through DOS. DOS controls the other attributes without your intervention.

Changing File Attributes with the ATTRIB Command

DOS's ATTRIB command provides the means to change the settings of the Archive, Read-only, Hidden, and System attributes. The syntax of the ATTRIB command is

ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] filespec [/S]

If you issue the ATTRIB command with no parameters, you get a list of all the files in the current directory, along with a display of their attribute status. Figure 5.1 shows a typical result.

The ATTRIB display when no parameters are given.

Figure 5.1. The ATTRIB display when no parameters are given.

As you can see in the figure, all the files have the Archive attribute set on. Also, all the files whose names begin with the letters R and G are marked as Read-only.

To change the attributes of files, use the first letter of each attribute's name and a plus (+) sign to set the attributes on or a minus (–) sign to set the attributes off. You can have any logical combination on one command line, such as the following:

ATTRIB -A +R

The preceding example turns off the Archive attribute and turns on the Read-only attribute for every file in the current directory. You can narrow the scope of the ATTRIB command by specifying a pathname expression (drive, path, and wildcards are honored) on the command line, as in the following:

ATTRIB -R G*.*

This example removes the Read-only attribute from only those files whose names begin with G. (You get a heavy dose of pathname expressions later in this chapter.)

You also can widen the scope of the ATTRIB command by using the /S switch. If you give ATTRIB a pathname expression as a parameter, by default the actions are limited only to the specified path. Giving no pathname expression to ATTRIB limits its action to the currently logged directory. Using the /S switch widens the scope of the ATTRIB command to include any directories under the directory where ATTRIB begins its actions.

Establishing Read-Only Files

The ATTRIB command gives you control over file attributes. In particular, the Read-only attribute makes DOS unable to overwrite a file. DOS commands such as EDIT, COPY, DEL, and XCOPY are capable of changing the data contained in a file. Files with the Read-only attribute cause a message to appear, telling you that the command you have tried to use cannot provide the service you are wanting.

In practice, however, the Read-only attribute has become little more than a confirmation flag to many modern programs. Both the DOS Shell and Windows File Manager can erase files having the Read-only attribute, for example, but only after you confirm that it is okay.

To give files the Read-only attribute, use the +R parameter, as in the following:

ATTRIB +R F:WSTAR*.TXT

Using the -R parameter has exactly the opposite effect, that of removing the Read-only flag.

Caution

The FDISK and FORMAT commands command do not observe the read-only status of a file. FDISK and FORMAT are disk-level commands; therefore, they don't look at disk directories when they are doing their jobs. Don't rely on the Read-only attribute of a file to protect the file from a disk-level command. Use the disk's write-protect tab to prevent floppies from being destroyed with FDISK and FORMAT.

Understanding the Role of Directories

To this point in the chapter, you have read many references to the directory. These references, although necessary for the explanations of files at the time, do not provide a great deal of information about directories. Now that you know all about files, however, it is time to turn your attention to the method used by DOS to organize files—directories.

In many homes, flatware is stored in a drawer in the kitchen. In some homes, the forks and knives and spoons are laid in a jumble, all mixed up. In other homes, a plastic tray that has compartments for each type of utensil is used. Forks stay with forks, salad forks have their own compartment, and so on. The capacity of the drawer to store flatware is not affected, but the drawer stays more organized. So it is with directories. DOS directories have the same purpose: They keep your files organized.

The root directory is an important table created by the FORMAT command on every disk it touches. It is called the root directory because it is the root, or beginning, of the disk's file system. DOS uses the directory as a kind of index system for finding files. The filenames and subdirectory names in this index system are called directory entries. DOS allows for a fixed number of directory entries in the root directory. This number is the same for disks with the same format but varies with different formats. Disks with larger capacities allow for more root directory entries. Although limited, the number of entries is generous. If you properly organize your disks, you will never even come close to this limit.

The DIR command is a window into the structure of a DOS directory. The DIR command accesses and displays selected parts of directory entries, as in this example:

C:>dir ??.bat

 Volume in drive C is DATA-TRAIN
 Volume Serial Number is 1A9A-BEDA
 Directory of C:

D4       BAT        39 09-18-90  12:51a
EE       BAT        34 04-23-92   4:05p
G        BAT        31 05-03-92   3:35a
HJ       BAT        28 12-10-92   6:34p
SK       BAT        26 08-27-90   3:23p
T        BAT        53 06-04-92   1:01a
W        BAT       128 05-25-92  10:49a
WP       BAT        16 08-27-91   3:46a
WS       BAT        35 12-05-90   2:40p
DP       BAT        37 09-06-91  10:37a
       10 file(s)        427 bytes
                  16,437,248 bytes free

C:>

As you can see, DIR lists the filenames, extensions, the number of bytes in the file, the date it was last written to disk, and the time of the last write. The DIR command, however, does not display all the elements of a directory entry. Table 5.4 lists the components of a directory entry.

Table 5.4. The Main Features of DOS Directories

Feature Example What Is Stored
Filename THANKYOU Eight-character file prefix
Filename extension DOC Three-character file suffix
File attributes R (read-only) Special status information about this file used by DOS
Time 10:22 The time of creation or last modification
Date 11-14-91 The date of creation or last modification
Starting cluster 576 The number of the first cluster allocated to this file by DOS in the FAT
File size 1024 bytes The number of bytes in this file

You undoubtedly recognize the filename, extension, time, and date components of a directory entry as the ones displayed by the DIR command. DIR also displays the file size. These components, or fields, of a directory entry contain information useful to you as well as to DOS (see Figure 5.2). DIR displays this information to assist your file-management activities.

The fields of a directory entry.

Figure 5.2. The fields of a directory entry.

Note

The easiest way to cause DOS to display the names of the current drive and directory is to place the following line in your AUTOEXEC.BAT file:

PROMPT $p$g

This line alters the default DOS prompt to show you the current pathname expression. For more information about PROMPT, see Chapter 11, “Controlling Your Environment.”

Note

DOS also stores volume labels in directory entries, using the combined filename and extension fields to form an 11-byte (11-character) field just like a filename. DOS knows that the directory entry is a volume label—not a filename—because the Volume Label attribute for the entry is set.

The starting cluster and file attribute fields, shown in Table 5.4 and in Figure 5.2, are not included in the DIR command's displayed output. The starting cluster field contains the cluster number of the first cluster DOS has allocated for a particular file's storage.

Expanding the File System Through Subdirectories

Earlier in this chapter, disk directories were likened to the plastic trays that many households use to organize eating utensils. The metaphor is not outlandish. This plastic tray separates similar utensils to make them easier to find; takes up very little room; and generally simplifies the storage of forks, spoons, knives, and so on. The DOS directory structure simplifies the storage of program and data files and makes them easier to find when needed.

When you use FORMAT to prepare a disk, it creates a root directory structure. The number of entries that this directory can contain is limited. On most floppy disk formats, the number of entries is limited to 512. On hard disks, the capacity is proportional to the size of the volume (logical disk) being created. There is very little chance that you will ever exceed the capacity, unless you try to store all the files on your hard disk in the root directory.

Imagine what chaos might reign if all your files were lumped together in one single directory. You would never be able to tell what files belonged with what program. Your data files from your word processor would all be scrambled up with files created by other programs, and every time you wanted to locate a file, the directory listing would go on for screen after screen.

To avoid these problems, DOS employs a method of creating subdirectories that branch off from the root directory. Subdirectories can in turn branch off into subordinate subdirectories. Figure 5.3 shows part of the display generated by the TREE command, which is used to represent the directory of a disk graphically.

Directories are used to organize the files on a disk.

Figure 5.3. Directories are used to organize the files on a disk.

Figure 5.3 shows the directory structure of a working disk drive. At the top of the tree, the E: represents the root directory. The vertical line that aligns with the E: shows the first level of directories, those that appear in the root directory. Two subdirectories, BRIEF and CLIPPER5, branch off from the root. The BRIEF directory in turn branches off four times to create four subdirectories to hold files associated with Brief, a programmer's editor. One of these subordinate directories contains Help files, another contains macro files, and so on. If you want to find a file containing a Brief macro, you use the DIR file to generate a listing, as in the following:

DIR E:BRIEFMACROS

It is unlikely that a Brief macro can work its way into the CLIPPER5LIB directory, so you can see that, by creating and maintaining directories, you can pinpoint easily the files you need to work with. In Chapter 13, “Controlling Devices,” you learn about the FIND command, which helps track down files that are not stored where you think they should be stored.

A good general system for creating directory structures is to have each application you install on your hard disk be contained within its own directory. The directory should have a name that tells you immediately what program resides in the directory. A good name for a WordPerfect directory is WP, for instance.

Installation programs for software applications often install files into directory structures created during installation. The Clipper programming language automatically creates a directory called CLIPPER5 and then places library, object, and binary files into subdirectories called LIB, OBJ, and BIN. It also creates other directories, but you get the idea.

Files associated with the main application can be made to reside in subdirectories that hold groups of files of the same types. The Clipper installation routine puts all the library files into the LIB directory. If later you create or buy other libraries from another source, you can copy them into the library directory, or you can create a directory that branches off the LIB directory to hold these files. You should do whatever makes them easiest for you and your software to find them.

Understanding Pathname Expressions

A pathname expression indicates the path that DOS must traverse to find a specified file or group of files. A pathname expression has three components: drive, directories, and files.

The drive component identifies the disk drive used to store the files. It is made up of three characters: the drive letter, followed by a colon (:) and a backslash (), as in the following example:

C:

DOS uses the backslash character to separate the directories within a pathname expression. The preceding example is a pathname expression that indicates the root directory of drive C because the backslash immediately follows the colon.

The directory component of the pathname expression is a list of all the directories that must be traversed to reach the last named directory or the file component. The following is an example:

C:WINDOWSSYSTEMGAMES

In this example, the pathname expression tells DOS to look for files by starting at the root directory of C:, moving into the WINDOWS directory, through the SYSTEM directory that branches from the WINDOWS directory, and then into the GAMES directory. Simply stated, a pathname expression gives DOS directions to directories, just like you might give a friend directions to your house.

The third portion of a pathname expression specifies a single file explicitly, or it uses wildcards to specify a group of files, as in the following two examples:

C:WINDOWSSYSTEMGAMESSOL.EXE

C:DOS*.COM

The first example specifies a single file in the GAMES directory, whereas the second example specifies a group of files using a wildcard. Pathname expressions can use ?, *, ., and .. as valid wildcard characters.

DOS requires each file on a disk to have a unique name. For this reason, DOS considers a file's full name to be the pathname expression that explicitly identifies that one file. For example, the name

C:DOSGO.BAT

is not the same as the following:

C:TEMPGO.BAT

Yes, two files have the name GO.BAT, but they are in different directories, so both files have a unique name.

If you issue the following command, which file's contents are displayed depends on what directory you are currently logged in to:

TYPE GO.BAT

If you are logged in to either the DOS or TEMP directories of drive C, you see the contents of the file named GO.BAT found in that directory. If you are logged in to the GRAPHIC directory, you might get a file not found message.

The trick to using pathname expressions effectively is knowing when to use the full formal pathname and when to use a less specific pathname expression.

People, like files, can be called either by a formal title, such as George W. Bush, President of the United States, or by a less formal form of address, such as President George Bush. Mr. Bush and George are other examples of names that identify the President. Pathname expressions can likewise be formal or informal.

The full formal pathname expression for a file expresses the location of a file or group of files explicitly without regard to the currently logged directory. This type of pathname expression is sometimes called an absolute path. The following is an example:

TYPE C:AUTOEXEC.BAT

This command displays the contents of your AUTOEXEC.BAT file onscreen no matter what drive or directory is currently logged. If, however, you currently are logged in to the root directory of C:, typing the C: portion of the pathname expression becomes optional because DOS always looks for a specified file in the current directory. Therefore, the following finds the proper file if you are logged in to C::

TYPE AUTOEXEC.BAT

This pathname formal expression uses a relative path to locate the file. Specifying a relative path involves giving directions to DOS, based on its currently logged directory. Each of the following three examples uses a relative path as its pathname expression:

DIR ..
DIR C:
DIR SAMPLES*.DOC

The first uses .. to cause DIR to show all files in the directory from which the current directory branches out. The second example lists all files in whatever directory is currently logged on drive C. The third example lists all the .DOC files in the SAMPLES directory, which branches off from the current directory.

Pathname expressions can range from the very simple to the very complex. Keep in mind two rules when you're creating directories on your system:

  • DOS pathname expressions cannot exceed 63 characters in length, including the implicit backslash DOS adds internally.

  • Typing long strings of directory names is both a pain in the neck and an invitation to typing errors.

If you really understand the second rule, you will never have a problem with the first rule. When you're creating directory structures on hard disks, keep the depth of directories to a minimum. When you are tempted to create a pathname that exceeds three directories deep, stop and think. At least half the time, you can come up with a better way to arrange directories so that you don't end up typing pathname expressions that sprawl across half the screen.

As complex as pathname expressions can become, most new users are surprised to find that they need learn only three simple commands to create and maintain DOS directories. The following sections provide a rundown of each command.

Creating Directories with MKDIR (MD)

DOS provides the internal MKDIR command to create directories. You can abbreviate the name of the command as MD for convenience. Because MD, or make directory, is easier to remember, this form is used in this chapter. Anywhere you see a reference to the MD command, you can substitute MKDIR.

The syntax for the MD command is as follows:

MD d:pathdirname

The command uses a pathname to explicitly describe the drive and pathway to the new directory to be created. You learn more about pathnames in the following paragraphs. For now, consider the following line:

MD E:BRIEFMACROSOLDMACS

This example creates the OLDMACS directory branching from the BRIEFMACROS directory. Subdirectory names are just directory entries in the parent directory. MACROS, for example, is just an entry in the BRIEF directory. What differentiates a subdirectory name from a filename is the Directory attribute. The starting cluster associated with the directory name is the first cluster on the disk where that directory's entries are written.

DOS naming rules allow a directory name to be up to 11 characters long. You can create a directory named STUFF.OLD, but by convention, DOS users have largely agreed to keep dir-ectory names to eight characters or fewer. When the DIR command lists a directory, subdirectories are marked with a <DIR> in the column where the size of a file is normally shown. Figure 5.4 illustrates how directory names are listed by DIR.

Directory names are marked with <DIR> to show that they are not files.

Figure 5.4. Directory names are marked with <DIR> to show that they are not files.

Tip

You also can use the MOVE command in certain circumstances to create new directories. Information about MOVE is presented later in this chapter and in Chapter 8, “Managing Your Files.”

As you can see, the DIR listing shows the directory structure for the root directory of E:. It contains several entries for subdirectories as well as three text files.

When you use the MD command, follow these guidelines:

  • The specified or implied parent directory of the intended directory must exist. If the JILL directory doesn't exist, MD JILLJACK fails.

  • MD cannot make more than one directory at a time.

  • MD does not change the current directory to the new directory. To change to the new directory, you must use CHDIR (CD).

If, for example, your current directory is DOS and you want to add the directory DOSDRIVERS, you can issue the following command:

MD DRIVERS

Notice that no backslash appears in front of the new directory name. DOS interprets this path to be a relative path, and it adds the current directory path to the pathname expression on the command line.

Changing the Current Directory with CHDIR (CD)

As you work with drives and files in DOS, you can consider each directory to be a location and the pathname expression of the directory to be its map. DOS keeps in memory your current location on each drive of your machine.

Use the CHDIR command to change from one directory to another. The short form of CHDIR is CD, meaning change directory. If you are in the WINDOWS directory and you want to work in the SYSTEM directory that branches off the WINDOWS directory, issue the following command:

CD SYSTEM

The WINDOWSSYSTEM directory then becomes your currently logged directory. DOS remembers which directory is current for each drive in your system. When you switch to another drive, DOS automatically retains a memory of where you were working last. Consider this example:

C:
CD DOSUTILS
F:
COPY *.BAT C:

In this example, you move onto drive C and change directories to the DOSUTILS directory. The next command moves you to drive F and copies all the batch files in the current directory of F: to the current directory of C:. In this case, the files are copied to C:DOSUTILS.

Note

To change directly to the root directory of the currently logged disk from any directory on the disk, issue the following command:

CD 

Also, if you are not sure what directory you are currently in, issuing the CD command with no pathname expression causes DOS to display the full pathname expression for the current directory.

You can also issue the following command to return to the directory above your current one (for example to move from C:DATADOCS to C:DATA):

CD ..

You can use either a relative path or an absolute path to specify what directory to change into. Assume you are currently logged in to C:DOSUTILS, for example, and issue the following command:

CD ..STUFF

This example uses a relative path to log you in to the C:DOSSTUFF directory. You also can log in to the same directory by issuing this command:

CD DOSSTUFF

When you're using the CD command, follow these guidelines:

  • The drive and path parameters in the command line must be valid.

  • If the path parameter begins with , CD assumes that the directory specified in the path is absolute—from the root.

  • If the path parameter does not begin with , CD assumes that the directory given in the path is relative to the current directory.

  • When you specify a drive parameter but no path parameter, CD reports the current working directory for the specified disk.

  • When you omit the path parameter and the drive parameter from the command line, CD reports the current working directory of the currently logged drive.

Deleting Directories with RMDIR (RD)

Just as you occasionally need to add a directory to a disk, you might need to delete a directory. DOS enables you to remove empty directories at the end of a directory branch in the directory tree with the RMDIR command, RD for short.

When you're working with the RD command, remember that RD can delete only empty directories. If a directory contains files or has another directory branching from it, RD fails. To delete a directory using RD, use a command similar to the following:

RD COLDHOTWARM

If the WARM directory is empty, RD removes it from the directory tree.

Using DELTREE to Delete Directories

The DELTREE command, new in DOS 6.0, makes the RD command obsolete. DELTREE enables you to delete directories that contain files—even complete branches of a directory tree. This command removes the directory you specify and everything in it—subdirectories, files, and files in subdirectories. In addition, attributes of files in the subdirectories are ignored. You do not need to use ATTRIB to clear attributes such as Read-only or Hidden before you delete them.

The syntax for DELTREE is as follows:

DELTREE /Y d:path

The optional d: parameter specifies the disk that contains the directory branch to be removed. If you omit d: from the command line, DOS assumes that the current (logged) disk holds the directory to be removed.

The required pathname expression specifies the topmost level of the directory branch to be removed. If the path begins with a backslash (), DOS assumes that the path to the directory name is absolute from the root. If the path parameter does not begin with a backslash, DOS assumes that the path to the directory name is relative from the current directory of d:.

The /Y parameter is optional. Because DELTREE is a potentially dangerous command, capable of wiping out hundreds of files at a time, DOS normally displays the following message:

Delete d:path and all its subdirectories? [Y/N]

If you type Y and press Enter, the command proceeds; if you type N and press Enter, the operation stops. If you use the /Y parameter, however, the message does not appear, and DELTREE proceeds as though you had typed Y.

Caution

DELTREE deletes everything in its path. As with anything in computing, a feature that gives you a great deal of power also gives you the ability to shoot yourself in the foot. Be sure you no longer need anything in any of the directories subordinate to the one you name before proceeding. To make sure, first issue the DIR command (with the /S parameter) or the TREE command, which is discussed later in this chapter.

Assume, for example, that your hard disk has a string of directories branching off from the root directory of C:. The pathname expression that specifies the lowest level directory is C:HOTCOLDWARMTEPIDICY. If you issue this command, all the files and directories in the WARM directory are deleted regardless of file attributes:

DELTREE /Y C:HOTCOLDWARM

Any directories that may branch off from WARM, TEPID, or ICY are also deleted, along with any files they contain.

As you can see, DELTREE is a powerful command. Always double-check your command line for errors before you press Enter to activate the command.

Remember, too, that you can use wildcards in the pathname expression of the command line, but use them only with caution. If a wildcard in a pathname expression matches both directory names and filenames, both are deleted. It is often a good idea to use the DIR command first to see what files the pathname expression affects before using that pathname expression with DELTREE.

Renaming Directories

Having to change the name of a directory is not uncommon. This need might arise because you misspell the name of the directory during creation or because you have upgraded software and want the upgrade to be reflected in the directory name.

The MOVE command enables you to rename directories from the command line and also moves files from one directory to another. The syntax of the MOVE command for renaming directories is as follows:

MOVE d:oldpath d:newpath

The optional d: parameter specifies the disk that contains the directory branch to be removed. If you omit d: from the command line, DOS assumes that the current (logged) disk holds the directory to be removed.

This command requires two pathname expressions. The first specifies the directory you want to move or rename. The second pathname expression specifies the new name of the target directory or the name of a directory to be created as a result of the command's actions. If the directory does not exist, MOVE prompts you to ask whether the directory should be created. Answer Y, and the new directory is created.

To rename a directory, use the MOVE command as in the following example:

MOVE C:TEMPBAK C:TEMPBACKUP

Helping DOS Find Files with PATH

When you issue a DOS command, COMMAND.COM, the command interpreter, looks first to see whether the command is internal to DOS. If the command is not internal, DOS looks on the disk for a filename having the same name as the command.

In this regard, both external DOS commands and other executable files have equal status. Files having the extensions .EXE, .COM, and .BAT are all considered by DOS to be executable program files. DOS simply looks for any executable file having the same name as the command-line keyword. It then runs the first file it finds.

Note

The DOS search path works only with executable files. If a program uses auxiliary files such as overlays and data files, an error can occur unless the program is written to search its own directory, not just the currently logged directory.

None of DOS's external commands use auxiliary files, so you never have a “file not found“ problem as long as the DOS directory is included in the search path. To run applications that use auxiliary files, you should log in to the directory where the application is written to disk to ensure error-free operation.

You have three ways to make sure DOS finds an external program file. You can do any of the following:

  • Log in to the disk and directory that contains the command

  • Supply the path in the command line

  • Establish a DOS search path to the command's directory

The PATH command places a path search string in the DOS environment. DOS uses the contents of this environment variable to determine where on the system it should look for program files.

Normally, the PATH command is included as a statement in the AUTOEXEC.BAT file, so it takes effect even before the first DOS prompt is displayed. Using the PATH command, however, is not restricted to lines in AUTOEXEC.BAT. You can type a new search string at any DOS prompt. Whether it is in a batch file or typed at a DOS prompt, the PATH command is used the same way, as in the following example:

PATH C:;C:DOS;D:WINDOWS;E:BRIEF

If you enter a command at the DOS prompt and COMMAND.COM does not recognize it as an internal DOS command, DOS always looks first in the currently logged directory. If the file cannot be found there, DOS uses the PATH information to first search the root directory of drive C, then the DOS directory of C:, then the WINDOWS directory on D:, and finally the BRIEF directory on E:. Only after searching all five directories for an executable file, and not finding it, does DOS give you the dread Bad command or file name message.

The directories you want searched are listed on the command line separated by semicolons (;). The order in which the directories are listed is the order in which they are searched. For this reason, it is prudent to keep the DOS directory and other frequently used directories at the front of the search string.

In the preceding sample PATH command, DOS is directed to first look in the root directory of drive C. This directory is traditionally a favorite repository for batch files that automate the launching of applications. The second directory specified is the DOS directory. The DOS directory should always be at or near the beginning of the search path because files in this directory are constantly being called on. Having the DOS directory at the head of the search path cuts down on the time spent searching for external DOS commands. Exceedingly long search paths can dramatically slow down your computer's response time.

The order of the search path is important for another reason as well. If two directories have executable programs with the same names, the program that is run is the one whose directory is specified closer to the beginning of the search path.

Although the maximum length of the search path is 127 characters, avoid creating long search paths. Traditionally, search paths are used mainly to allow DOS to find often-used utilities without having to change logged drives or directories. Having too many directories in the search path slows down system performance because it takes DOS longer to determine whether a command is valid. Some software applications, such as Windows, require an entry in the search path for efficient operation, however. In general, if you seldom use the executable files in a directory, it is better to leave that directory out of the search path.

Listing Directories with TREE

DOS provides an external command, TREE, that lists all the directories of a disk as a tree structure similar to the DOS Shell's directory display. Figure 5.4 shows the TREE command's output. The TREE command also can list the files in the directories. TREE is especially useful when you're working with hard disks because it visually maps out the directory structures of disks.

The TREE command syntax is as follows:

TREE d:path /F/A

d: is an optional parameter that indicates the drive whose directories you want to list. If you omit d:, TREE lists the directories on the current disk drive.

The path expression names the directory where TREE is to start processing the listing. If you omit this parameter, TREE begins processing from the root directory.

TREE accepts two switches. The /F switch instructs TREE to display the files contained within directories as part of the visual tree. The /A switch instructs TREE to use printable characters instead of the line-drawing characters normally used to indicate branching of directories. Use the /A switch when you're directing output to an older printer that cannot print graphics characters or when using a text-only video adapter.

Using a Temporary Directory

Many programs and some DOS operations use a directory as a temporary location to store scratchpad files. A scratchpad file is a file that is created as a buffer to store information temporarily before a permanent file is created. A good example of a program that uses temporary storage space is Windows. Windows creates .TMP files in the temporary directory to hold swapping information. Also, the Windows Print Manager uses the temporary directory to create files to hold print jobs. Other programs use temporary space as a place to store sorting information, backup copies of files being processed, and so on.

Traditionally, DOS users have created a directory called TEMP that branches off the root directory of C:. In fact, if this directory doesn't exist when you install DOS 6.22 using the Setup program, it is created for you automatically.

The SET command, which creates DOS environment variables, normally is used in AUTOEXEC.BAT to create a variable called TEMP, as shown in this example:

SET TEMP=C:TEMP

When DOS or another program needs to create temporary files, it looks in the environment to see whether a TEMP variable exists. This way, you can direct DOS to use a specific directory. If you don't have a TEMP directory, most software uses the currently logged directory to create scratchpad files. You should always make sure that the TEMP directory resides on a disk with plenty of free space. Lack of scratchpad space can make programs run much more slowly than normal or display an error message.

Caution

Most programs that create scratch files do a good job of cleaning up after themselves by deleting any files they might create when the files are no longer needed.

It is a good idea to check the TEMP directory every few days just to make sure that no scratchpad files have been orphaned by a power failure or untimely reboot. If you find files in the TEMP directory, you should delete them.

Be careful, however, not to delete files in the TEMP directory while you're running Windows or when you're shelled out to a DOS session from within a running application. Under these circumstances, the files still might be active and in use. Never delete files from the TEMP directory unless you are at a DOS prompt with no other programs running.

Troubleshooting

What happened to my filenames?

Modern operating systems, such as Windows 95/98/ME and Windows NT/2000, enable you to have filenames up to 256 characters. A common problem occurs when a user copies files with long filenames to a DOS machine that supports only the 8.3 filename format. DOS renames a long filename by truncating it and adding a tilde (~) and a numeric character.

If you copy the file CONVERTIBLE.EXE to a DOS machine, for example, you end up with a file called CONVER~1.EXE.

If you try to name a file with an illegal character or with too many characters in the extension, you encounter other errors. The following example uses the COPY command to show what can happen:

COPY TEST.TXT 123456789.1234

Notice that both the filename and extension given for the destination filename contain an extra character: The filename has the extra character 9, and the extension has the extra character 4. You might predict that DOS will issue a message warning that the filename and extension are too long. No such luck! DOS simply truncates the filename to eight characters and the extension to three characters to create a legal filename (12345678.123), and then it completes the COPY operation.

Illegal characters in a filename can prevent DOS from carrying out a command. Here's an example:

COPY 12345678.123 1[3.123

This command causes DOS to display the following message:

File creation error

Few experienced DOS users purposely use illegal characters in a filename, but typos easily can creep into your DOS commands and introduce illegal characters into filename parameters. Type commands carefully, remembering that DOS's reaction to an illegal filename isn't always predictable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.35.72