Chapter 8. Managing Your Files

Using DOS to Work with Files

After you have installed DOS on your computer, created your directories, and installed programs, in a sense you have set up housekeeping on your PC.

Most programs generate files as you work with them. You begin to accumulate files on your computer's disks in much the same way that you accumulate possessions in your home or office. Fortunately, DOS provides useful file-management commands that help you keep file clutter to a minimum. This chapter covers file-management techniques.

One of the most difficult things to do in this age of multiple-gigabyte hard drives is to keep track of all the information stored on your hard drive. By creating a directory structure that segregates groups of files according to their uses, you can keep the files on your computer's hard disk organized and cataloged. The adage “a place for everything and everything in its place” is never more true than when you're storing files on a large hard disk.

It is important that you understand the distinction between utility programs and applications when devising a strategy to manage files using DOS. A utility is generally regarded as a single-purpose program that performs one specific task and then gets out of your way. An application generally provides a working environment capable of providing all the services required to perform general tasks such as word processing and creating pictures.

DOS's external commands are perfect examples of utilities. Each external command serves a specific purpose, such as sorting lists or formatting disks. You usually run a utility program by typing a command line at the DOS prompt. It does its work and then terminates, giving you another DOS prompt to work from. Utilities usually have all their programming contained in a single EXE or COM file, and they seldom use auxiliary files. It therefore is most often convenient to place utility programs into directories that are part of the search path so that they are available no matter what directory you are logged in to. By default, most utilities act on files in the currently logged directory.

Applications, even though they might be dedicated to a single activity such as word processing or database management, have a much broader scope. Unlike utilities, which do their job and terminate to a DOS prompt, applications create a working environment in which users can access the features of the applications. Only when you exit an application do you receive another DOS prompt.

Applications usually are installed into a directory of their own. They often use auxiliary files such as overlays—a special type of file that contains the programming code necessary to provide a subset of the application's features. These auxiliary files often make it necessary or convenient to log in to an application's home directory before running the application. This isn't a hard-and-fast rule because some utilities also create files. The most notable feature of an application, in the context of this discussion, is that it most often creates files having a specific format unique to the application. WordPerfect creates WordPerfect files, Lotus 1-2-3 creates 1-2-3 files, and so on.

In terms of working with files, the distinction between utilities and applications is simple. Utilities most often work with files in place—that is, in the location (directory) where they were created. Applications, on the other hand, usually work with files in specific directories created to store files that have the native format particular to that application.

Tip

When you're creating directory structures on your hard disk, it is usually a good idea to create dedicated directories for your applications where those applications can store the files you create. Doing so enables you to find a particular file more easily when you need it.

Listing Files with the DIR Command

The DIR command is one of the first commands most DOS users learn. It also is the most-used command in the DOS inventory. The command quickly gives you a list of your files, along with the date and time you created them, and the file sizes. If you type only DIR, you are using only a fraction of the command's full power. The following sections help you unlock the power of the DIR command.

Note

By default, many applications create files in their home directories when installed. Many of these applications have dozens of auxiliary files (overlays, printer drivers, video drivers, and so on). For this reason, it is a good idea to create one or more directories—branching off an application's home directory—where files created by the application are stored.

Many applications have settings that can specify which directory newly created files should be written in. Check the documentation for your applications to find out how to set up default directories for newly created files.

Issuing the DIR Command

DIR is an internal command. All the programming for this command is contained in COMMAND.COM, so you will never find DIR.EXE in your DOS directory. The syntax of the DIR command is as follows:

DIR FileNameExp /P /W /A:attributes /O:order /S /B /L

FileNameExp is a filename expression that can contain the drive, path, and file specification. Of course, the filename expression can include wildcards.

The DIR command also uses several switches. These switches and their definitions are shown in Table 8.1.

Table 8.1. DIR Switches

Switch Action
/P Displays one screen of information and then pauses. Pressing any key causes DIR to continue the listing.
/W Displays only the filenames, without the size, date, or modification time of the files. Files are listed in columns across the screen rather than one filename per line.
/A:attributes Displays only files that have, or lack, file attributes you specify, such as read-only, hidden, or system files.
/O:order Lists files in a different sorted order, such as alphabetical order by name.
/S Lists the contents of subdirectories.
/B Lists filenames only, one per line.
/L Lists all filenames in lowercase.
/C Displays the file compression ratio.
/CH Displays the file compression ratio using the host allocation unit size.

When you issue the DIR command with parameters missing, DOS uses default values. If you omit the filename expression, DIR uses the currently logged directory. Unless you use the /O switch, files and directories are listed in their regular, unsorted order.

Understanding the Operation of the DIR Command

When you issue the DIR command, the volume label and serial number of the disk are displayed along with a filename expression that specifies what directory is being displayed. Files and subdirectories are then displayed in the following format unless you specify the /W switch:

CIS      ZIP     55,029 08-01-01  11:47p
DISCPASS     <DIR>      06-16-01   3:10a

The first line of the example shows the standard format for files. Directory information is divided into five columns. From left to right, they are as follows:

  • Filename

  • Extension

  • Size of the file in bytes

  • The last date the file was edited

  • The time of day the file was last edited

The second line of the example shows how directories are displayed. The <DIR> symbol indicates that the entry is a directory and thus doesn't have a byte count.

The information displayed by DIR includes most of the data stored in the directory table. The file attributes do not appear, but DOS uses them to determine whether to display a file. By default, hidden files are not included in this list. The location of the first cluster in the file allocation table (FAT) for the file also is not displayed because knowing the file's starting cluster is of little use to you as a user.

At the end of the listing, DOS indicates the total number of files in the directory, the total number of bytes used by the listed files, and the total number of bytes free on the current disk. The DIR report for C:DOS, for example, might show the following information:

157 file(s)    6,455,328 bytes
             119,504,896 bytes free

If you add the size of each of the listed files on the disk and subtract the result from the total disk capacity, that number and the number of free bytes shown in the directory listing probably do not match, but the directory listing is correct. Remember that hidden files are not shown; more importantly, the size of the file is not necessarily the same as the amount of disk space it occupies.

You might remember from earlier chapters that a cluster is the smallest possible chunk of disk space that can be allocated. When you create a file, no matter how small, DOS allocates at least one cluster to store the file. The directory listing shows the length of the data stored in bytes and calculates the free space, based on the number of free clusters on the disk. These free clusters are the remaining positions on the disk, not yet allocated to another file.

The free space reported by DIR is the number of unallocated clusters (also called allocation units) multiplied by the size of a cluster (1,024 bytes on most hard disks). You also can use CHKDSK to get a report of the total number of allocation units available on the disk.

Displaying a Screen of Information with the DIR Command

If you add the /P switch to the DIR command, DOS pauses the scrolling of the screen at the end of each screen of information. Pressing any key displays the next page of information.

To see more filenames, use the /W switch. When you use this switch, a directory listing like the one shown in Figure 8.1 appears.

Using the /W switch to see filenames presented in wide format.

Figure 8.1. Using the /W switch to see filenames presented in wide format.

With hierarchical directories, your directory listing includes subdirectory names and files. In the wide listing, directory names are enclosed in brackets ([]). Because the filenames are grouped so closely together, a wide listing can be useful when you want to see the types of files in a directory.

Using the Attributes Switch (/A)

When you specify the /A switch, only those files having the attributes you include on the command line are listed in the DIR display. The /A switch uses one or more of the following codes for the attributes parameter:

D Directory attribute
R Read-only attribute
H Hidden attribute
A Archive attribute
S System attribute

If you include the /A switch with no attributes parameter, DOS lists all filenames—even the filenames of hidden and system files—regardless of file attribute. To see only a listing of all hidden files in the current directory, enter the following command and press Enter:

DIR /AH

You can use attribute codes in any combination and in any order. You can list all filenames with the read-only and archive attributes, for example, by issuing the following command:

DIR /ARA

DOS lists only filenames that have both attributes.

To list only filenames that do not have a certain attribute, insert a minus sign (–) before the attribute code. To see all files that are not directories and that don't have the archive bit, for example, type the following command at the command line and press Enter:

DIR /A-A-D

Using the Order Switch (/O)

As mentioned earlier, the /O switch enables you to choose the order in which DOS lists filenames. When you want DOS to sort the file list in a particular order, use the /O switch with the following sort codes:

C Sorts files by compression ratio
D Sorts files chronologically by date and time
E Sorts files alphabetically by file extension
G Groups directories first before showing files
N Sorts files alphabetically by name
S Sorts files numerically by file size

You can include sort codes in any combination. The order of the sort codes determines the final sorted order. /ONE, for example, sorts the filenames first by name and then by extension. The command DIR /OEN sorts files by extension (for example, grouping all .COM files together and all .EXE files together) and then sorts the files by name. If you include the /O switch in a DIR command without specifying a sort code, DOS sorts the files alphabetically by name.

DOS assumes that all sorting is to be done in ascending order—A through Z, smallest to largest, earliest to latest. DOS uses these criteria (the default setting) unless you precede your sort codes with a minus sign (–) to force the sort into reverse order—Z through A, largest to smallest, latest to earliest.

Using the /B and /L Switches

You can use the /B switch to display a “bare” file list—a list of filenames without information about file size and the date and time the file was last changed. The following is an example:

DIR A: /B

DOS lists all filenames of the files in the current directory of the floppy disk in drive A. For this example, DOS does not list file size or file date and time.

Tip

Another way to view directory listings, especially for extremely long listings, is to pipe the information to a text file for later viewing or printing. To do so, you use the > symbol after the DIR command and then specify a filename as follows:

DIR > dirlist.txt

This technique is especially helpful if you want to use the information in another program, such as Word, because you can cut and paste from the text file.

If you want to capture the file list to a file, issue a command similar to this:

DIR A: /B >FILES.TXT

You can use the /L switch with the DIR command if you want the filenames to appear in lowercase letters.

Searching for Files with the DIR Command

No matter how carefully you construct your directory structures, occasionally you lose a file. Most of the time you simply forget where you put a particular file. Sometimes, however, you lose the file because you have mistyped a filename expression. When you look in the directory in which you think a file should reside, it is missing. Other times, you simply forget the exact name of the file you're looking for.

The DIR command is an effective tool for finding “lost” files when you use the /S switch. Entering the following command causes DOS to display every file written to drive C:

DIR C:  /S

You can, of course, use filename expressions and other DIR switches to narrow the scope of the search. The following example lists all the .DOC files in WordPerfect's directory as well as all the directories that branch off the WP directory:

DIR C: WP *.DOC /S

Assume for the moment that you have created budget spreadsheets using your spreadsheet software and that you have saved these spreadsheets on your hard disk. You want to make a copy of the budget spreadsheet files, but you cannot remember the directory in which they are located. However, you do remember that all the filenames start with the letters BUDG. You can use the DIR command to search the hard disk for the location of the files. To do so, change to the root directory of your hard disk and then type the following command:

DIR BUDG*.* /S

When you press Enter, DOS displays a listing similar to this:

 Volume in drive C is DCI 3
 Volume Serial Number is 1B2B-392C

Directory of C: SPREADSH QPRO4DAT

BUDGET   WQ1       4,037 10-05-01   2:00a
        1 files(s)       4,037 bytes

Directory of C: WORD_PRO ENDATA

BUDGET   WK1       5,120 04-07-01   8:51p
        1 files(s)       5,120 bytes

Total files listed:
        2 files(s)       9,157 bytes
                   119,504,896 bytes free

Note

As you have seen, you can use the DIR command to locate files if you know something about their filenames. But what do you use if you know only that the file contains the text “Meet me in St. Louis, Louie,” and that the string is to be found in one of three files? In this case, you use the FIND command. Because FIND is useful in various situations, it is covered in detail in Chapter 13, “Controlling Devices.”

Customizing the DIR Command

If you find that you continually use one or more of the several switches with the DIR command, you can avoid typing them repeatedly by creating an environment variable named DIRCMD using the following command:

SET DIRCMD=switches

For the switches parameter, substitute the switch or switches you want DOS to use automatically. If, for example, you want DOS to sort filenames alphabetically and pause scrolling after each screenful of information, include the following command in your AUTOEXEC.BAT file:

SET DIRCMD=/ON/P

Then, reboot the computer. DOS creates the environment variable DIRCMD and gives it the value /ON/P. Each time you issue the DIR command, DOS adds these two switches automatically.

You can override a switch that is recorded in DIRCMD by preceding the switch with a minus sign (–). To override the /P switch currently recorded in DIRCMD, for example, so that DOS lists all filenames without pausing at the end of each screen of information, issue the DIR command shown here:

DIR /-P

Viewing Files

After you find a file, you often need to peek into it to find out what it contains. Knowing what a file contains is crucial to knowing how to best work with the file. DOS provides tools to enable you to look into files.

Previously, you learned that DOS stores files on disks in binary format—using zeros and ones. You learned that these binary digits, grouped in bundles of eight, form bytes. You also read that each byte can form one of 256 values called the ASCII code, which represents letters, numbers, computer commands, and so on. That description is fine as far as it goes, but it is a simplistic view that doesn't present the whole picture.

→ For more information on how DOS stores data, see Chapter 6, “Understanding Disks and Disk Drives,” p. 127.

A computer uses bits and bytes in many ways. The microprocessor in your computer is designed to use binary digits in groups of eight, true. But those binary digits can be used in different contexts. Each bit in a byte might be used to indicate the status of a condition, with 1 meaning on and 0 meaning off. Large numeric values, such as a spreadsheet might use, might be stored in two or four bytes, which are translated into decimal numbers that users understand. Bytes also are used to deliver instructions (program code) to your computer's microprocessor.

Understanding these contexts isn't at all important for you to be able to work with your computer, but knowing that these contexts exist makes it much easier to work with files. When you need to view the contents of files, having this knowledge is essential.

Understanding Types of Files

From a user's point of view, files fall into two categories: binary and ASCII. Binary files are not understandable by humans. When you try to look into them, they appear to be gibberish. Strings of smiley faces, hearts, and a slew of weird-looking symbols are interspersed with letters and numbers to produce an unintelligible display. When you see this kind of display, you know you have opened a binary file.

ASCII files use bytes to represent the symbols you use to communicate every day: letters, numerals, punctuation marks, and so on. An ASCII file is the simplest file format used by DOS. When DOS displays or prints an ASCII file, the groupings of binary digits are directly translated into a human-readable format. ASCII files also are referred to as DOS text files, or simply text files.

Unless you are programming, binary files are of little interest to you. DOS does provide the DEBUG command to view and edit binary files, but you had better know what you are doing. The DEBUG command is documented in Appendix F,“Command Reference,” for the sake of completeness, but its use is far beyond the scope of this book. It is enough for you to know that if you open a binary file, you can look all you want, but under no circumstances do you want to change anything or do a disk save on the file, even by accident. Changing even one byte in an executable file can render a program useless and can even be dangerous to your data.

→ DOS provides two commands for viewing the contents of ASCII files: EDIT and TYPE. The EDIT command enables you to view and edit files. For complete information on EDIT, see Chapter 15, “Using the DOS Editor,” p. 361.

Using the TYPE Command to View Files

When you need to see the contents of an ASCII text file, you can use the TYPE command. By redirecting the output of TYPE, you can print a hard copy of the file.

The syntax for the TYPE command is as follows:

TYPE filename.ext

Replace filename.ext with the name of the file you want DOS to display. (Remember to include a disk drive and pathname, if necessary.) A filename is not optional. Wildcard characters are not permitted because TYPE can display the contents of only one file at a time.

TYPE is designed to display the contents of a text file that contains ASCII characters. When you issue a TYPE command, DOS opens the specified file and sends the file's contents to the screen as ASCII characters. When DOS encounters a Ctrl+Z character (ASCII decimal 26; the end-of-file character), it stops displaying the contents of the file and returns to the command prompt.

When you use TYPE to view a text file, the file's contents can fill and begin to scroll off the screen faster than you can read the text. You can press Ctrl+S or the Pause key (available only on the Enhanced Keyboard) to stop scrolling, but the text you want to see might already have scrolled off the screen. The MORE filter displays a screenful of a command's output and then pauses until you press a key. You can use MORE with the TYPE command as follows:

TYPE AUTOEXEC.BAT | MORE

The | character in this command is the DOS pipe character, which instructs DOS to send a command's output to the filter that follows the pipe character. Piping to MORE causes DOS to pause the scrolling of the screen when the screen fills. You can press any key to display the next screenful.

→ For detailed information on DOS redirection and MORE, see Chapter 13, “Controlling Devices,” p. 317.

Tip

An even easier way to display an ASCII file one screen at a time is to redirect a file into the MORE command without using the TYPE command. To do so, use the following syntax:

MORE < d:pathfilename.ext

The < symbol causes DOS to use the specified file parameter as input to the MORE filter. DOS displays the file, one page at a time, displaying the message -More- at the end of each page. To display a file in the C:DOS directory, for example, type the following command (replacing filename.ext with the filename and extension of the file you want to view), and press Enter:

MORE < C: DOSfilename.ext

If you want a simple printed copy of the contents of a text file, you can redirect the output of the TYPE command to the printer by using the special redirection character, the greater-than sign (>). To print the contents of the README.TXT file, for example, make sure that your printer is online and then issue the following command:

TYPE README.TXT >PRN

Your printer prints the file. (Because TYPE does not format the text into pages, the printed output might not break at page boundaries.)

When you use the TYPE command, remember the following guidelines:

  • The output of TYPE stops when the command encounters the first Ctrl+Z in the file.

  • Because TYPE does not accept wildcards in the filename parameter, use of the command is limited to one file at a time.

  • TYPE tries to interpret any file as an ASCII text file, even if the file contains non-ASCII data. If you use a binary file (such as a COM or EXE file) as the file parameter, the TYPE command's output might produce graphical characters, control-character sequences, and beeps. Its output might even lock up your computer, forcing you to reboot.

  • You can pause the TYPE command's output by pressing Ctrl+S or Pause. Press any key to resume scrolling.

  • You can terminate the TYPE command's output by pressing Ctrl+C or Ctrl+Break.

Copying Files

Probably the most common file-related function is copying files from one disk or directory to another, a fundamental job for disk operating systems. MS-DOS provides the internal COPY command for use at the command line. Copying files via the DOS Shell is covered in Chapter 4, “Using the DOS Shell.”

The DOS COPY command enables you to copy files as well as data to and from logical devices. Figure 8.2 diagrams the copy operation used with several possible inputs and two possible outputs. Three of the possible inputs consist of more than one file or logical device. DOS can join two or more inputs into one output in a process called combining. You might never need to use all these inputs and outputs, but they're available.

Possible inputs and outputs in a copy operation.

Figure 8.2. Possible inputs and outputs in a copy operation.

Using the COPY Command

You can create a COPY command line in various ways. All the variations say the same thing to DOS: “COPY THIS THERE.” The THIS represents the source—the files to be copied. The THERE represents the target—the disk location or device you want the files to be copied to.

When you perform a copy operation, remember the following guidelines:

  • The source parameter must contain at least one of the following parameters: path, file, or device.

  • If the file specification portion of a filename expression is omitted, all files in the specified directory and drive are copied. This situation is equivalent to supplying *.* as the source-file parameter.

  • You can specify additional source-file parameters by using the + operator to combine the files.

  • If the source-file parameter contains a wildcard and the destination parameter is a filename, the destination file is the combination of source files that match the source-file parameter.

  • If COPY detects an attempt to copy a single source file to itself (same drive, directory, filename, and extension), the copy operation is aborted.

  • The optional destination parameter consists of a combination of drive, path, and filename parameters. If you don't provide a drive or path, DOS uses the current drive or path for the destination. If you don't specify a destination filename, DOS uses the source file's name as the destination parameter.

  • COPY is definitely a versatile file-management workhorse, but you do have to be careful. An incorrect COPY operation can do nearly as much damage as an incorrect DEL command because the destination file's entries in the FAT and in the directory are not saved as they were, making file recovery all but impossible. Be sure to treat COPY with respect. Many programs include warning messages as part of their internal file copying commands. The COPY command gives no warning when it is about to overwrite existing files.

In a COPY command, the order of the parameter requirements always moves from the source to the destination, or target. The full syntax for the COPY command is as follows:

COPY SourceExpression TargetExpression /V /A /B /Y

The SourceExpression and TargetExpression parameters specify either a filename expression that specifies one or more files or a DOS device, as in the following example:

COPY STUFF.TXT PRN

In this example, the file STUFF.TXT (an ASCII text file) is copied to the printer to produce a hard copy of the file's contents. Use COPY to print ASCII files only because files containing word processor codes, graphics, or file headers don't result in clean reproductions of the file's content.

For combining files, the source expression can be two or more filename expressions that specify a single file, joined with the + symbol, as in this example:

COPY MEMO1.TXT + B: MEMOS MEMO2.TXT  H: MYMEMO.TXT

In this example, the file MEMO1.TXT, located in the currently logged directory, will be combined with a file located in the MEMOS directory of drive B to create a file having the name MYMEMO.TXT on drive H.

As you can see, you can use four switches with the COPY command: /V, /A, /B, and /Y. The /A and /B switches can be applied to individual filename expressions in both the source and target expressions. The following list details the uses of the COPY switches:

  • The /V switch verifies that the copy has been recorded correctly.

  • When /A is used in SourceExpression, files are treated as ASCII; that is, COPY copies all the information in the file up to, but not including, the first end-of-file marker (ASCII decimal 26). DOS ignores anything after the end-of-file marker.

  • When /A is used in TargetExpression, an end-of-file marker is added to the end of the ASCII file after it is copied.

  • When /B is used in SourceExpression, COPY copies the entire file (based on its size, as listed in the directory) as though the copied file were a program file (binary). Any end-of-file markers are copied.

  • When /B is used in TargetExpression, it does not add the end-of-file marker to the end of the copied data.

  • The /Y switch indicates whether you want COPY to overwrite files with the same name without prompting. You can use the /-Y switch to indicate that you want to be prompted.

Copying Groups of Files

Suppose that you have 20 files you want to copy to a floppy disk or to another directory on your hard disk. You can use wildcards in the filename expression to specify a subset of the files in a directory, as in this example:

COPY C: ROCCANTI *.TXT B:

This example finds all the .TXT files in the ROCCANTI directory and copies them onto the floppy disk in drive B. You do, of course, have to make sure that the disk in drive B has enough room to receive the files. Use the DIR command to find out how many bytes the files to be copied require and to make sure that at least that much space is available on drive B.

If you want to copy all the files in a directory to another disk or another directory, use a command similar to this:

COPY E: CLIPPER5 INVNTRY *.* H: TEST

In this example, the *.* wildcard expression specifies that all files in the INVNTRY directory are to be copied to the TEST directory on drive H.

Tip

Some older keyboards do not have a conveniently placed key for the asterisk. You might want to use the . wildcard to specify all files in the directory, as in this line:

COPY E: CLIPPER5 INVNTRY . H: TEST

This command is functionally equivalent to the preceding example using the *.

Combining Text Files

Although you can use COPY to combine any files, the combine operation is most effective when the files are ASCII text files. In most cases, combining binary files results in an unusable destination file.

For the following examples, assume that the current directory contains three text files, all with .TXT extensions. The files and their contents are listed here:

File Contents
INTRO.TXT Combining is
BODY.TXT the joining of files
ENDING.TXT into a new file.

To join the three files into a fourth file, type the following command:

COPY INTRO.TXT+BODY.TXT+ENDING.TXT ALL.TXT

The resulting file, ALL.TXT, contains the text from the three source files. To verify ALL.TXT, issue the following command:

TYPE ALL.TXT

TYPE sends the contents of ALL.TXT to the screen. DOS displays the following output:

Combining is the joining of files into a new file.

Note

If you omit the target expression, or specify only drive and path information in the filename expression, the file created by combining files has the same name as the first filename specified in the source expression.

Renaming Files with COPY

As you might guess from the examples in the preceding section, you can change the name of a file or group of files by using COPY. Consider this example:

COPY *.TXT *.ASC

This example copies all the files in the current directory having the extension TXT. Each TXT file is copied to an ASC file. The ASC files have the same names as the original TXT files. The contents are the same and the names are the same—only the extensions are altered.

Copying from a Device to a File

A common and handy use of the COPY command is copying to a file keystrokes entered from the keyboard or console device. (CON is the device name for console, a device constructed using your keyboard and monitor.) You can use the resulting text file as a batch file, a configuration file, a memo, and so on.

To practice copying from the keyboard to a file, you can create a simple batch file that changes the current directory to 123R3 and starts Lotus 1-2-3 Release 3. The command that creates the batch file is shown here:

COPY CON C: DOS RUN123.BAT

When you press Enter, DOS displays the cursor on the next line, but the DOS prompt does not appear. You can type the file by following these steps:

  1. Type C: and press Enter. The cursor drops to the next line.

  2. Type CD123R3 and press Enter. The cursor drops to the next line.

  3. Type LOTUS and press Enter. The cursor drops to the next line.

  4. Press the F6 function key or Ctrl+Z to indicate the end of the file. DOS displays the end-of-file marker (^Z).

  5. Press Enter. The ^Z code indicates to DOS that you are finished entering data into the file. DOS responds with the message 1 file(s) copied.

To confirm that the new file appears the way you want it, you can use the TYPE command to review its contents.

Note

If you try this example on your system, be sure to use the appropriate directory names for DOS and Lotus 1-2-3.

Knowing how to use COPY CON can be both a lifesaver and a pain in the neck. It can be a lifesaver because COPY CON enables you to create a text file on any DOS system. It also can be a pain in the neck because after you have pressed Enter to go to the next line, you cannot go back and edit previous lines. If you make a mistake, you must start over again.

If the DOS EDIT command—found only in version 5.0 and later—is available, or if some other ASCII editor is available, use it. You are much better off using the editor instead of the COPY command because you can more easily correct any typos you find.

Using the XCOPY Command

The external command XCOPY is an enhanced version of COPY that, among other capabilities, can copy whole directories and their subdirectories while creating directories on the destination disk.

Using XCOPY, you can exercise much more control over the files to be copied. You can copy only those files with the archive attribute set, for example, or only those files with a date stamp on or after a specified date.

The syntax of XCOPY is similar to that of COPY, but the switches are more complex. The XCOPY syntax is as follows:

XCOPY SourceExpression  TargetExpression /V /P /W /S /E /A /M /Y /D:date

Just like the COPY command, XCOPY takes filename expressions to specify the source files and the target files for the operation. Unlike COPY, XCOPY has several switches that enable you to finely control how the copy is performed. Following is a rundown of the available switches:

  • /V verifies the accuracy of the copy operation by comparing each file as it is written to the original file.

  • /P displays a prompt to confirm whether you want to create each destination file. Using /P, you can specify a group of files with a wildcard and then decide which files you actually want to copy. If, for example, you want to copy several files in a directory but don't want to enter five separate COPY commands, you can use the following:

    XCOPY *.TXT B: /P
    

    As each file is about to be copied, XCOPY prompts you to see whether that file is to be copied. Answer Y and the file is copied; answer N and it is skipped.

  • /W causes XCOPY to pause before copying any files, displaying the prompt Press any key to begin copying file(s). You can pause to change disks.

  • /S causes XCOPY to copy the files located in any directories that branch off from the source directory. Empty directories are ignored.

  • /E causes XCOPY to copy even empty directories.

  • /A causes XCOPY to copy only files with the archive attribute set without modifying the file's attributes.

  • /M causes XCOPY to remove the archive bit from any files copied.

  • The /Y switch indicates whether you want XCOPY to overwrite files with the same name without prompting. You also can use the /-Y switch to indicate that you want to be prompted.

  • /D enables you to specify a date parameter. XCOPY copies only files with a date attribute on or after the specified date. Which date format you use depends on the country setting you use.

In an XCOPY operation, DOS might not always recognize whether a particular parameter refers to a file or to a directory. When ambiguity arises, XCOPY asks whether the destination is a filename or pathname.

Note

All files created by XCOPY have the archive attribute set automatically, even if the original source file does not have the archive attribute.

Consider the following command:

XCOPY C: WORDS *.* A: WORDS

If no directory named WORDS exists on the destination disk, DOS cannot determine whether you intend to create a file or a directory named WORDS on the A disk.

XCOPY displays the following message:

Does WORDS specify a file name
or directory name on the target
(F = file, D = directory)?

Press F when the destination (target) is a filename or D when the destination is a directory. Unlike COPY, XCOPY creates directories on the destination disk as needed.

If you append a backslash to the name of the target directory, XCOPY automatically assumes that the target is a directory, not a file. Continuing the preceding example, if you use the following command instead, you do not have to specify that the target is a directory:

XCOPY C: WORDS *.* A: WORDS

XCOPY creates the WORDS directory if it does not exist.

Understanding the Operation of XCOPY

XCOPY is best described as a hybrid between COPY and BACKUP/RESTORE. XCOPY and COPY duplicate files between directories and disks. Unlike COPY, however, XCOPY does not copy files to a nondisk device, such as the printer (PRN) or console (CON). Like BACKUP and RESTORE, XCOPY can copy files selectively and traverse the directory tree to copy files from more than one directory. XCOPY also can make a destination directory when one does not exist. This directory capability makes XCOPY useful for duplicating a directory branch onto another disk.

Like COPY but unlike BACKUP, XCOPY copies files that are directly usable. (You cannot use files processed by BACKUP until you have processed them with RESTORE.)

When using the XCOPY command, consider the following guidelines:

  • XCOPY cannot copy hidden source files.

  • XCOPY does not overwrite read-only destination files.

  • If a file parameter is omitted in the XCOPY syntax, XCOPY assumes the *.* full wildcard pattern as the default file parameter.

  • If you include the /D switch, you must enter the date parameter in the format of the system's DATE command or in the format indicated by the latest COUNTRY command.

  • The /V switch performs the same read-after-write checking as the SET VERIFY ON global verify flag.

To use XCOPY to copy empty source subdirectories, you must specify both the /S and /E switches.

Tip

The XCOPY command is one of the most useful DOS file commands available. To copy the source files of an entire program (such as Windows 95) to the hard drive, for example, it is much easier to use the XCOPY command with wildcards and the /S switch (to copy subdirectories) than to attempt to drill down and copy each directory by itself with the COPY command.

Using XCOPY Effectively

Using XCOPY, you can control by date or archive attribute the files copied, you can copy complete subdirectory trees, and you can confirm which files to copy. The command has several ideal uses: copying files selectively between disks or directories, performing a quick hard disk backup (backing up only a few critical files in several subdirectories), and keeping the directories of two or more computers synchronized.

With COPY, your control is limited. COPY duplicates all files that match the given name—an all-or-nothing approach. If you use the /P switch with XCOPY, however, DOS asks whether you want to copy each file.

Using XCOPY is practical if you want to make backup copies of something less than a disk full of files from several directories. Rather than BACKUP, you might prefer to use the command XCOPY /A to select files that have changed since the last backup.

Tip

Keep the following points in mind when you use XCOPY to back up a disk:

  • If you suspect that the files cannot fit on one disk, be sure to use the /M switch. As XCOPY copies each file, the command resets the file's archive attribute bit. When the destination disk is full, XCOPY stops. At this point, you can change disks and restart the XCOPY command, again using the /M switch. XCOPY copies the files whose archive bit has not yet been reset.

  • XCOPY cannot break a large source file between destination disks. If you need to back up a file that doesn't fit on a single floppy disk, you must use BACKUP.

  • A favorite use of XCOPY is to synchronize the contents of the hard disks of two computers. Many people have one computer at work and another at home. If both computers have hard disks, keeping the copies of programs and data files current is a major task. Which files did you change today? Which machine has the more current version?

  • When you want to keep separate hard disks synchronized, you might find the XCOPY command's /A, /D:date, and /S switches especially useful. The /S switch forces XCOPY to traverse your disk's directory structure, playing a hunting game for source files. Whether you use /A or /D depends on how often you copy files between the machines. If you copy files between the machines frequently, you might prefer the /A switch. If you allow many days to pass between synchronizing your computers' contents, you might find that the /D switch works better. Use /D if you have run BACKUP on the source machine since you last used XCOPY. BACKUP resets the archive attribute so that the command's /A switch does not catch all files changed between XCOPY backups.

→ For more information on backing up files, seeUnderstanding Microsoft Backup,” p. 233.

Duplicating Disks with XCOPY

The XCOPY command can be used to create duplicate floppy disks, even when the disks are different sizes or formats. You can't make a disk hold more than its capacity, of course, so you can't use XCOPY to copy a full 1.44MB floppy disk onto a 720KB disk. You can, however, transfer the contents and directory structures of a 1.2MB 5 1/4-inch disk to a 1.44MB 3 1/2-inch disk, or a 720KB 3 1/2-inch disk to a 1.2MB or 1.44MB disk. Assume that you have a 720KB disk with several levels of directories in drive B, for example, and you want to copy it to a 1.2MB disk in drive A. To do so, you issue the following command:

XCOPY B: A: /S

Duplicating a Directory Branch

For this example, assume that your hard disk has a subdirectory named WPFILES that contains a few word processing files. WPFILES also has two subdirectories. The first, WPFILESMEMOS, contains your current memos; the second, WPFILESDOCS, contains your document files. You want to keep a current set of the files in these three directories stored on a floppy disk. To copy all the files in this directory branch to the floppy disk, issue the following command:

XCOPY C: WPFILES A: WPFILES  /S

XCOPY immediately begins to read the source directories. DOS displays the following messages:

Reading source file(s)...
C: WPFILES LET9_1.WP
C: WPFILES LET9_2.WP
C: WPFILES LET9_3.WP
C: WPFILES LET9_4.WP
C: WPFILES LET9_5.WP
C: WPFILES DOCS SCHEDULE.DOC
C: WPFILES MEMOS SALES.MEM
     7 File(s) copied

Because you included the /S switch, XCOPY copied the files in C:WPFILES, C:WPFILESMEMOS, and C: WPFILESDOCS. The A:WPFILES path parameter causes XCOPY to ask whether the name specifies a directory or a file. WPFILES conceivably can be a user file in the root directory. The full pathname of each file is echoed to the screen as the file is copied to drive A. When the command finishes, the WPFILES directory branch has been copied to drive A.

As another example, assume that your PC experiences a hardware failure and needs to go to the shop for repairs. You want to use your floppy disk that contains the WPFILES directory branch to place that directory branch on a second computer's hard disk. To do so, enter the following command:

XCOPY A: C: /S

XCOPY reverses the copy process described in the preceding paragraphs by copying all the files on drive A to corresponding subdirectory locations on drive C.

Copying Entire Disks with DISKCOPY

The external DISKCOPY command makes exact duplicates of a disk. Duplication is so complete that even file fragmentation is preserved. If the target disk has not yet been formatted, DISKCOPY automatically formats it before performing the duplication.

DISKCOPY does have one major limitation. You can copy only like media to like media. A 1.2MB disk, for example, can be successfully copied only to another 1.2MB disk. You cannot use DISKCOPY to duplicate a 720KB floppy disk on a 1.44MB disk. See the section on using XCOPY to duplicate disks earlier in this chapter for information on duplicating unlike disks.

The syntax for DISKCOPY is as follows:

DISKCOPY SourceDisk TargetDisk /1 /V /M

The source disk is the drive letter that holds the original disk to be duplicated. The target disk is the optional name of the drive that holds the disk to receive the copy. This destination drive is sometimes called the target drive. If you don't specify a drive name for the target, DOS assumes that you want to use the current drive and prompts you to insert and remove source and destination disks as necessary.

Only three switches are recognized by DISKCOPY. The /1 switch causes DOS to copy only the first side of a double-sided disk. This switch, which is a holdover from old versions of DOS, enables you to copy single-sided disks. Chances are, you will never need the /1 switch.

The /V switch instructs DOS to verify that the copy and original are identical. This switch slows down operations by adding the extra comparison step. You use this switch only when you are working with disks that you will never have an opportunity to copy again and you need to make absolutely sure you got a clean copy.

The /M switch forces DISKCOPY to work in memory only. Using this switch means that DISKCOPY does not use temporary files on your hard disk to aid in duplication. Instead, all operations are performed in memory. This method of operation effectively forces you to swap disks during the copy, as was required in older versions of DOS.

Note

If you leave out the drive names in the DISKCOPY command line, DOS uses the current drive as the specifier. If you have a system with only one disk drive or if the second disk drive supports only different formats, you can simply issue this command:

DISKCOPY

Remember to log on to the drive you want to use before issuing the command. DOS prompts you to insert the source disk and target disk at the appropriate times.

The following is the classic example of the DISKCOPY command:

DISKCOPY A: B:

This example assumes that both drive A and drive B contain disks having the same capacity. After you issue the DISKCOPY command, DOS prompts you to insert the disks into the proper drives. Make sure that you insert the disks into the correct drives. Write-protect the source disk to safeguard its contents in case of a disk mix-up.

When the disks are in place, you are ready to continue. Press any key to start the DISKCOPY process. When the process is complete, DOS asks whether you want to make another copy. Press Y to copy another disk or N to exit the command (see Figure 8.3). If the drives or disks are not compatible, an error message appears, and nothing is copied (see Figure 8.4).

A typical DISKCOPY command sequence and messages from DOS.

Figure 8.3. A typical DISKCOPY command sequence and messages from DOS.

An error copyingdisksDISKCOPY commanddiskscopying (DISKCOPY command)commandsDISKCOPYcopying disksDISKCOPY commandcopying disksmessage produced by the DISKCOPY command.

Figure 8.4. An error message produced by the DISKCOPY command.

Moving Files

In early versions of DOS, if you wanted to move a file from one place to another, you had to first copy the file and then delete the original. Now DOS enables you to move files from one location to another using the MOVE command.

The MOVE command's syntax is similar to the syntax for COPY. In effect, the syntax of the MOVE command says, “MOVE THIS THERE.”

In a MOVE command, the order of the parameter requirements always moves from the source to the destination, or target. The full syntax for the MOVE command is as follows:

MOVE SourceExpression(s) TargetExpression /Y

Caution

If you omit a path parameter from both the source and target, you either copy or rename the source file, depending on whether the specified target filename exists. If the name exists, you copy the source file over the target file, eliminating the target file. If the name does not exist, you rename the source file.

If your source parameter includes only one file, you can rename the file as you move it by specifying a new filename or extension as part or all of the target parameter. If your source parameter includes more than one file, you cannot use a filename and extension parameter as part of the target parameter. If you do so, however, DOS assumes that you want the target file to be the target for all the files to be moved, and the message Cannot move multiple files to a single file appears. You must, however, specify either a drive or directory as the target.

The /Y switch indicates whether you want MOVE to overwrite files with the same name without prompting. You also can use the /-Y switch to indicate that you want to be prompted.

As an example of how to use MOVE, suppose you want to move a file called BUDGET01.WQ1 from a directory called C:SPREADSHQPRO4DAT to a directory called D:OLDFILES (assuming neither directory is current). In this case, you enter this command:

MOVE C:SPREADSHQPRO4DATBUDGET01.WQ1 D:OLDFILES

If the move is successful, DOS displays the following message:

c:spreadshqpro4datudget01.wq1 => d:oldfilesudget.wq1 [ok]

Caution

If the source and target parameters represent the same file, DOS erases the file without warning you.

Moving Directories and Files

You can use MOVE to move files from one directory to another. If the target directory doesn't exist, the MOVE command creates it. Figure 8.5 shows the MOVE command moving all the files in H:TEST to a new TEST directory on drive G.

Moving all the files in a directory.

Figure 8.5. Moving all the files in a directory.

As you can see in the figure, the source expression specifies that all the files in the TEST directory on drive H are to be moved to a directory called TEST on drive G. Because the directory doesn't exist on drive G, MOVE prompts you to make sure that you intend to create a new directory to hold the moved files. As each file is moved, MOVE displays the original name, a => symbol, and the new name of each file.

The MOVE command has no effect on H:TEST other than to remove the files from the directory. The source directory is not deleted from drive H. Also, the MOVE command pays no attention to the read-only file attribute. Even files marked read-only are moved.

Renaming Directories with MOVE

Another use for the MOVE command is to rename a directory, as shown in the following example:

MOVE C: MEMOS  C: LETTERS

The effect of the sample command is to rename the MEMOS directory as LETTERS without affecting the files contained in the directory.

Setting Defaults for COPY, XCOPY, and MOVE

If you are using DOS 6.22, you can use a new environment variable to specify how you want all three file-management commands—COPY, XCOPY, and MOVE—to work. The COPYCMD environment variable is similar to the DIRCMD environment variable discussed in the section “Customizing the DIR Command” earlier in this chapter; it sets default switches that DOS uses whenever you issue the COPY, XCOPY, or MOVE commands.

The command to set the COPYCMD environment variable is as follows:

SET COPYCMD=switches

For the switches parameter, substitute the switch or switches you want DOS to use automatically. If, for example, you do not want DOS to prompt you when it is about to overwrite a destination file, include the following command in your AUTOEXEC.BAT file:

SET COPYCMD=/Y

Then reboot the computer. DOS creates the environment variable COPYCMD and gives it the value /Y. Each time you issue the DIR command, DOS adds this switch automatically.

You can override a switch that is recorded in COPYCMD by preceding the switch with a minus sign (–). To override the /Y switch that is currently recorded in COPYCMD (so that DOS tells you when it will overwrite a file), for example, issue the COPY command as shown here:

COPY /-Y

Renaming Files

If copying files is the most common file-related function of DOS, renaming files probably follows close on its heels. The reasons for renaming a file are many. You might want to use the current filename for another file, or perhaps you want to create a name that better describes the contents of the current file. Whatever the reason, DOS enables you to rename a file using the internal command RENAME. Like some other DOS commands, RENAME also has a short form, REN. Which form you use depends on how you feel about typing three extra letters.

The DOS rename operation changes the name in a file's directory entry, but the file and its physical location on the disk remain unchanged. Because two files in the same directory cannot have the same name, DOS does not change a filename if the new filename already exists.

The syntax for RENAME is either of the following:

RENAME OldExpression NewExpression

REN OldExpression NewExpression

The REN command requires two parameters. OldExpression is a filename expression that specifies the files to be renamed. NewExpression is a filename expression that specifies what the new names of the files will be. Consider this example:

REN MEMO.TXT MEMO12.TXT

This example renames the file MEMO.TXT as MEMO12.TXT.

You also can use wildcards to specify groups of files to be renamed. Suppose, for example, that you have a group of files named MEMO1.TXT, MEMO2.TXT, and so on in your directory. To rename them, you can issue this command:

REN MEMO?.TXT LTR?.DOC

The result is that MEMO1.TXT is renamed as LTR1.DOC, MEMO2.TXT becomes LTR2.DOC, and so on.

When you use RENAME, remember the following guidelines:

  • You can use the commands REN and RENAME interchangeably at the command line. Both commands produce identical results.

  • You must supply both an old filename and a new filename. The filenames can contain wildcards for DOS to use in pattern matching.

  • You cannot use the RENAME operation to move a file from one directory or disk to another directory or disk.

Note

If you are not sure which files a wildcard parameter will match, issue the DIR command, using the wildcard pattern that you plan to use in the filename parameter. DIR lists the matching filenames. Study these names carefully to see whether using the wildcard pattern with the RENAME command will produce the result you expect.

Comparing Files

MS-DOS 6.22 contains a program called FC that allows you to compare files to verify their integrity. For example, if you have your entire company's budget in a file and you wanted to make a copy of it to store offsite, using the FC command to verify that the copied file is exactly the same would provide an additional verification that it is a valid copy. The following sections will describe how to use the FC command effectively.

Comparing Files with FC

The external command FC (meaning file comparison) compares two files or two sets of files to find differences in the files. Any differences are reported onscreen. When a copied file is extremely important, you can use FC to compare the file with the original. If differences are found, you know that a problem might exist with the copy. Normally, DOS detects data integrity errors while reading and writing files, but if you want to be sure that two files are the same, you can ease your mind by using FC.

Note

PC DOS versions 1.0 through 5.0 and MS-DOS versions 3.3 through 5.0 include a simpler file comparison command, COMP. This command, however, is less versatile than FC, provides less information, has fewer options, and cannot compare files of different lengths.

The FC command has two general syntax forms. One form uses the /B switch for a forced binary comparison; the other form uses the remaining switches in an ASCII comparison. The two forms of syntax are as follows:

FC /B SourceExpression TargetExpression

FC /A /C /L /LBn /N /nnnn /T /W SourceExpression TargetExpression

The source expression specifies the originals of the files to be compared. If you use wildcard characters in this parameter, all files matching this parameter are compared with the second file.

The target expression specifies the files to be compared to the originals. Usually, you need to specify only the drive and directory part of a filename expression. FC compares those files specified in the source expression that can be found in the target directory.

Note

If you use wildcard characters in both the source and target expressions, FC compares the files as sets. That is, only those files whose names match in other respects are compared.

If you use the command FC *.WK1 *.BAK, for example, FC compares each worksheet file having the extension .WK1 with the worksheet file having the same base name and the extension .BAK. AUGSEPT.WK1, for example, is compared with AUGSEPT.BAK. FC does not compare every worksheet file with every backup file.

The switches used by FC enable you to control the operations of the command more tightly. The switches used are as follows:

  • /A instructs FC to abbreviate its output (DOS 3.2 and later versions), displaying only the first and last lines of each set of differences separated by an ellipsis (…).

  • /B performs a binary (byte-by-byte) comparison, showing the hexadecimal address and value of every differing byte.

  • /C causes FC to ignore the case of alphabetic characters when making comparisons; thus, c = C.

  • /L instructs FC to compare the files in ASCII mode, even when the files have EXE, COM, SYS, OBJ, LIB, or BIN extensions (DOS 3.2 and later versions).

  • /LBn sets the number of lines in the FC command's buffer to n. The default number is 100 (DOS 3.2 and later versions). If the number of consecutive nonmatching lines exceeds the buffer size, FC aborts the compare operation.

  • /N instructs FC to include the line numbers of lines reported in the output (DOS 3.2 and later versions).

  • /nnnn establishes the number of lines that must match after a difference in order to resynchronize FC.

  • /T instructs FC to view tab characters as literal characters rather than tab-expanded spaces (DOS 3.2 and later versions).

  • /W instructs FC to compress whitespace—tabs, empty lines, and spaces—into a single space for purposes of file comparison.

Understanding the Operation of FC

FC works in two modes: ASCII and binary. It defaults to ASCII mode comparison when the files to be compared do not have extensions (EXE, COM, SYS, OBJ, LIB, or BIN) that traditionally indicate binary files.

In ASCII mode, FC compares two files line-by-line. Lines from both files are held in a line buffer. FC uses the lines in the buffer to compare the first file to the second.

If FC detects a difference, it displays the first filename followed by the last matching line and the mismatching line or lines from the first file. It then displays the next line to match in both files.

After displaying mismatch information about file 1, FC repeats the same sequence for file 2. The file 2 name is displayed first, followed by the last matching line and the mismatching lines from file 2, ending on the next line that matches in both files, thus synchronizing the two files.

FC can help you determine whether the contents of two files are different by showing you the extent and location of any mismatch it finds. You can use this output as an alternative to a side-by-side comparison of the file contents.

Tip

If you are comparing two files that are not the same, you can quickly stop the reporting of differences by pressing Ctrl+C or Ctrl+Break.

In binary mode, FC compares two files byte-for-byte. At the first difference, the byte offset position in the first file is reported along with the value of the two files' bytes at that position. The offset and byte values are reported in hexadecimal (base 16) form. This form of FC is essentially equivalent to the older COMP command.

In binary mode, FC does not attempt to resynchronize the two files by finding an adjusted point of byte agreement. If one file has an additional byte at one place in the file, FC reports the additional byte and all subsequent bytes of the file as mismatches.

If one file is longer than its comparison file, the binary mode compares as many bytes as are present and then reports that one file is longer. When a binary file comparison results in a long listing of differences, you might want to stop the FC operation by pressing Ctrl+C or Ctrl+Break.

Only one switch is available in the binary mode. The /B switch causes the comparison to be binary even if file extensions indicate that the files are not binary. You use the /B switch to compare two text files in binary mode. You might find situations in which you prefer to have the binary-mode output format of FC than the ASCII mode format. Binary mode format reports differences as pairs of hexadecimal values. You then can see the values of characters, such as Ctrl+G (bell), that do not produce printed output.

When you use FC, keep in mind that the default number of lines that must match in an ASCII comparison after a difference has ended is two. The files are then considered resynchronized. Using the /nnnn switch, you can change the number of “must match” lines by setting nnnn to the desired value.

Using FC to Compare a Copied File to Its Original

Suppose that you are copying the ANSI.SYS file from your hard disk to a floppy disk to use for an important demonstration on another PC. When the copy is complete, you set the disk on the edge of your desk and go to the break room to get coffee. When you return, you notice that the disk has fallen off your desk and landed against the small transformer that runs your cassette recorder. You are worried that the magnetic field from the transformer has damaged ANSI.SYS. To verify that the copied ANSI.SYS file is good, you can compare it to the original by using the following command:

FC A:ANSI.SYS C: DOS DRIVERS ANSI.SYS

After a few seconds, FC reports FC: No differences encountered. The copy of ANSI.SYS seems to be good.

Comparing Two Text Files

Suppose that two similar text files, ORIGINAL.TXT and ANOTHER.TXT, are located in the default directory of the current drive. ORIGINAL.TXT contains the following text:

This is the first line.
This is the second line.
1
2
3
4
5
This is the last line.

ANOTHER.TXT contains the following text:

This is the first line.
This is not the third line.
1
2
3
4
5
6
7
8
9
This is the last line.

Note that ANOTHER.TXT has four more lines than ORIGINAL.TXT and that the second lines of the files contain differing text. These simple files illustrate how FC reports differences. You can use the principles illustrated here to understand the result of comparisons of more complex files. If, for example, you want to compare the two files that are in the same directory, you issue the following command:

FC ORIGINAL.TXT ANOTHER.TXT

FC makes the following report:

Comparing files ORIGINAL.TXT and ANOTHER.TXT ***** ORIGINAL.TXT
This is the first line.
This is the second line.
1
***** ANOTHER.TXT
This is the first line.
This is not the third line.
1
*****


***** ORIGINAL.TXT
5
This is the last line.
***** ANOTHER.TXT
5
6
7
8
9
This is the last line.
*****

FC displays the lines before and after the mismatched line, if any exist. It also finds mismatches that are not on equivalent lines so that it can match text even when one file contains material not found in the other. The second report concerning ANOTHER.TXT shows all the lines between the one containing the numeral 5 and the one containing the text This is the last line. Only these two matching lines appear in the report concerning ORIGINAL.TXT.

Comparing Disks with DISKCOMP

You can confirm that two disks are identical by using the external command DISKCOMP, which compares each track of one disk to each track of another disk sector-by-sector. Like DISKCOPY, DISKCOMP is a floppy-only command; you cannot use DISKCOMP to compare two hard disks. Furthermore, the disk types and capacities must be the same for both disks in the comparison; any difference in disks made with DISKCOPY is a sign of a problem disk.

One practical use of DISKCOMP is comparing a master disk included with a software package to a working copy of that disk. DISKCOMP confirms whether the working copy is good.

Normally, you use DISKCOMP to test disks that were made from originals with the DISKCOPY command. Because DISKCOMP doesn't write any information to either disk, both disks can be write-protected. If the disks are identical, DOS displays the message Compare OK.

The syntax for DISKCOMP is similar to that for DISKCOPY. The syntax for DISKCOMP is as follows:

DISKCOMP SourceDisk TargetDisk /1 /8

The source disk is the original, and the target disk is the copy. DISKCOMP recognizes only two switches. The /1 switch causes DOS to compare only the first sides of the disks. The /8 switch compares only the first eight sectors of each track on the disks. Both of these switches provide backward compatibility for testing floppy disks made with very old versions of DOS.

An example of the DISKCOMP command is as follows:

DISKCOMP A: B:

When the first DISKCOMP operation is complete, DOS asks whether you want to compare another disk.

In the sequence shown in Figure 8.6, a working copy of a master disk is being compared to the original master. Notice the comparison errors. The working copy no longer is reliable, or other files have been added to the disk since DISKCOPY was used to make a working copy from the master. The best way to solve the problem is to make a new working copy.

Comparing a working copy of a master disk to the original disk.

Figure 8.6. Comparing a working copy of a master disk to the original disk.

If you issue the DISKCOMP command with no drive parameters, DOS uses only one drive to carry out the comparison and prompts you to insert the first and second disks alternately. Depending on your system's memory, you swap disks once or several times. By entering DISKCOMP alone, without parameters, you tell DOS to use the current floppy drive even if your system has two floppy drives. Make sure that you don't mix up the disks when you're swapping them. If you don't keep track of which disk DOS wants in the drive, you might end up comparing part of a disk to itself.

Deleting Files

Because no disk has unlimited storage space and because nearly every file eventually becomes obsolete, DOS provides a way for you to erase or delete files from your disks. The internal ERASE command enables you to delete files you no longer need.

Unlike other DOS commands' short forms, the ERASE command's short form is not simply an abbreviation of the keyword. The short form of ERASE is DEL. Because the short form is shorter, thus quicker to type, it is generally used rather than ERASE.

When you delete a file, DOS locates that file in the directory and marks the directory entry with a special internal indicator. DOS considers this space to be available for reassignment when a new file is added to the directory. By reclaiming a deleted file's directory entry, DOS can control the expansion of a subdirectory or reclaim one of the limited root directory entries.

Understanding the Delete Operation

The delete operation does not affect the contents of a file's allocated clusters. Deleting a file does not record over the file's data in the way erasing a cassette tape records over existing audio. Rather, DOS alters its bookkeeping records in the directory and in the file allocation table. The directory entry for the file is “deleted” by changing the first character of the filename to an unprintable character (E5 hex), and the FAT cluster chain for the file is deallocated. DOS marks the file's clusters as being “free.”

The DOS bookkeeping records for the deleted file remain relatively intact until another file is added to the directory or until another file is expanded or added in any directory. The UNDELETE utility (discussed in Chapter 9, “Protecting Your Data,”) takes advantage of the fact that DOS does not erase a file's content when you delete the file. UNDELETE “fixes” the deleted file's directory entry and reconstructs the deleted file's cluster chain. If another file has been added, however, the UNDELETE command might not be capable of recovering the deleted file because DOS might have reallocated some or all of the storage space assigned to the deleted file.

The syntax for deleting files is either of the following:

DEL FileNameExpression /P

ERASE FileNameExpression /P

The filename expression specifies the drive, the directory, and/or the name of the files to be deleted. You can use wildcards to specify multiple files.

Using the optional /P switch causes DEL (or ERASE) to prompt you for confirmation before DOS deletes each file. Press Y to instruct DOS to delete a file or press N to skip the file without erasing it.

When you are executing a delete operation, remember the following guidelines:

  • At the command line, the DEL (or ERASE) command does not erase files marked with the read-only, hidden, or system attribute.

  • The delete operation does not remove a directory, erase a volume label, or erase a hidden or system file.

  • If you specify a directory name as the filename expression on the DEL command line, DOS tries to delete all the files in the specified subdirectory.

Deleting Files from the Command Line

The internal DEL and ERASE commands remove files from the disk, returning to the disk the space occupied by the deleted files. When you use DEL or ERASE to erase a file, DOS no longer can access the file. The erased file's directory entry and storage space become available to DOS for storage of another file.

Caution

Because DEL (or ERASE) deletes files from your disk, use the command with caution. DEL accepts wildcards in the file parameter. A momentary lapse of your attention while you are using DEL can wipe out important data in the blink of an eye.

Deleting Unwanted Files

Suppose that you have completed and delivered a series of memos composed in your word processing program. That program automatically creates in the C:WP directory a backup file, with a BAK extension, for each memo. You want to keep the memo files on disk so that you can refer to them, but after the memos are safely delivered, you do not need the BAK files. You can erase the files with BAK extensions one at a time, or you can issue the DEL command as follows:

DEL C: WP *.BAK

In this command line, the *.BAK filename parameter instructs DOS to delete all the files with the BAK extension. When the DEL command completes its work, all files with BAK extensions are removed from the directory. Because this command line includes drive and path parameters, you can issue the command from any logged disk and current directory and still erase the BAK files in C:WP.

Using Interlnk to Share Another Computer's Resources

More and more users now have come to own more than one computer. Often they have a desktop machine in the office and a notebook or laptop computer they use when they travel. Although having two computers extends your computing power to places other than your office, having two computers also can make it difficult to keep data in both places up-to-date. Furthermore, it is not uncommon for two users in an office to need to share files, and maybe even a printer, at times.

The DOS feature called Interlnk enables you to access drives and printers on a remote computer as though they were part of your computer. You can use this feature to transfer files from a laptop or notebook computer to your desktop computer, to print files from your portable computer on a printer attached to your desktop computer, and even to run programs directly from the remote computer.

When you use Interlnk, one computer—the server—becomes the completely passive “slave” of the other. Before you start, decide which computer you want to work on. The server should be the computer with the resources—files or printers—that you want to use remotely.

Setting Up Interlnk

Interlnk uses two executable files. INTERLNK.EXE makes a machine the client. You must load this file into the computer by using the DEVICE command in CONFIG.SYS. After the Interlnk client software is loaded, it remains in memory as a terminate-and-stay-resident (TSR) application that responds to a set of commands not normally available in DOS.

INTERSVR is a command run from the DOS prompt. It completely takes over the system to act as an extension to the client computer running INTERLNK.EXE. You can run INTERSVR.EXE in a Windows-hosted DOS session, but while it's running, all multitasking activities in Windows are suspended.

Note

Interlnk is the name given to the features provided by INTERLNK.EXE and INTERSVR.EXE. INTERLNK and INTERSVR are commands provided by Interlnk. You can tell by the capitalization and the computer font whether the following sections are speaking of Interlnk features or the INTERLNK command.

→ Use DOS's multiple configuration feature to enable your computer to boot with or without INTERLNK.EXE loaded. For information on multiple configurations, see Chapter 2, “Starting DOS,” p. 23.

You need to have a special cable built for use with Interlnk. The cable connects one machine to the other and can use either a serial or parallel connection. You cannot use a standard printer cable because the connector pins of an Interlnk cable must follow the configuration shown in Table 8.2.

Table 8.2. Cable Configurations for Use with Interlnk

Pin Connections for Serial Port Connections
9 Pin 25 Pin  25 Pin 9 Pin
5 7 7 5[*]
3 2 3 2
7 4 5 8
Pin Connections for Serial Port Connections
9 Pin 25 Pin  25 Pin 9 Pin
6 6 20 4
2 3 2 3
8 5 4 7
4 20 6 6
Pin Connections for Parallel Port Connections
25 Pin  25 Pin   
2 15   
3 13   
4 12   
5 10   
Pin Connections for Parallel Port Connections
25 Pin  25 Pin   
6 11   
15 2   
13 3   
12 4   
10 5   
11 6   
25 25   

[*] Ground wire

Tip

You can use either a serial or parallel connection to wire the two computers together, but only a serial connection using all seven wires is capable of using the /RCOPY switch of INTERSVR. The /RCOPY switch enables you to connect to computers that do not have Interlnk already installed by copying INTERSVR.EXE to the remote computer and running it.

If you have only a 3-wire, or NULL modem, serial cable, or parallel cable, you need to carry floppy disks to put INTERSVR.EXE on the slave machine.

Loading INTERLNK.EXE

Interlnk uses a client/server metaphor to divide the responsibilities of the software. INTERLNK.EXE provides the client portion of Interlnk. The client module takes complete control of the server machine. Disks on the server appear to the client as though they are part of the client machine. Printers on the server are likewise made to appear as though they are attached to the client. INTERLNK.EXE is loaded at boot time via CONFIG.SYS. The syntax to load the Interlnk client portion, INTERLNK.EXE, is as follows:

DEVICE=d:path INTERLNK.EXE /DRIVES:n /NOPRINTER /COM:n | address
   /LPT:n| address /AUTO /NOSCAN /LOW /BAUD:rate /V

The filename expression d:path indicates the drive and directory where INTERLNK.EXE is written to disk. The other parameters are as follows:

  • /DRIVES:n specifies the number of redirected drives. The default is 3.

  • /NOPRINTER specifies that printers are not to be redirected. By default, all printers are redirected.

  • /COM:n |address specifies a serial port to be used for data transfer. The port can be specified as n, the port number, or the address of the port. If you specify the /COM switch without an accompanying /LPT switch, no parallel port is used. By default, Interlnk scans all available serial ports and uses the first port it finds connected to the server.

  • /LPT:n | address specifies a parallel port to be used for data transfer. The port can be specified as n, the port number, or the address of the port. By default, the first port found connected to the server is used. If you specify the /LPT switch without an accompanying /COM switch, no serial port is used. By default, all COM and LPT ports are scanned.

  • /AUTO causes Interlnk to be loaded only when a connection is detected. By default, Interlnk is loaded even when no client/server connection is detected.

  • /NOSCAN causes Interlnk to be loaded into memory but not activated until you issue the INTERLNK command. DOS does not recognize the INTERLNK command, however, unless the device driver has been loaded.

  • /LOW specifies that Interlnk is to be installed in conventional memory. By default, Interlnk is loaded into an upper memory block (UMB) if space is available.

  • /BAUD:rate is used only in serial communications to set the speed at which the two computers communicate through the serial cable. Valid rates are 9600, 19200, 38400, 57600, and the default, 115200. If you find serial communications unreliable, try lowering the baud rate to eliminate transmission errors.

  • /V is used for serial communications to prevent conflicts with the computer's timer. If one of the computers hangs up when you try to communicate, try the /V switch.

Normally, Interlnk scans all your drives and all your ports when this device driver loads. If you have a serial mouse and plan to run Microsoft Windows, add a parameter that tells Interlnk which port is connected to the remote computer. If you are using a second printer port for your connection, for example, type the following line:

DEVICE=C: DOS INTERLNK.EXE /LPT2

This command prevents Interlnk from examining all your serial and parallel ports (and from disrupting your mouse operations in the process).

Loading the Server

INTERSVR is an executable file, loaded from the command line, that suspends all the operations of the computer and gives control over the computer's resources to INTERLNK, running on the client computer. You do not have to load INTERLNK.EXE on the server to make an Interlnk connection.

If you load INTERSVR on a machine that is running a multitasking system such as Windows or QEMM, all background operations are suspended until you exit INTERSVR. The syntax to load the server portion of Interlnk, INTERSVR.EXE, is as follows:

INTERSVR.EXE /X=drives /COM:n | address /LPT:n| address
   /BAUD:rate /B /V /RCOPY
  • /X specifies the letter or letters of drives to be excluded from redirection. By default, all drives are redirected. If /X is used, any listed drives are unavailable to the client.

  • /COM:n | address specifies a serial port to be used for data transfer. The port can be specified as n, the port number, or the address of the port. If you specify the /COM switch without an accompanying /LPT switch, no parallel port is used. By default, Interlnk scans all available serial ports and uses the first port it finds connected to the client.

  • /LPT:n | address specifies a parallel port to be used for data transfer. The port can be specified as n, the port number, or the address of the port. By default, the first port found connected to the client is used. If you specify the /LPT switch without an accompanying /COM switch, no serial port is used. By default, all COM and LPT ports are scanned.

  • /BAUD:rate is used only in serial communications to set the speed at which the two computers communicate through the serial cable. Valid rates are 9600, 19200, 38400, 57600, and the default, 115200. If you find serial communications unreliable, try lowering the baud rate to eliminate transmission errors.

  • /B causes the Interlnk screen to be displayed in monochrome.

  • /V is used for serial communications to prevent conflicts with the computer's timer. If one of the computers hangs up when you try to communicate, try the /V switch.

  • /RCOPY is used to copy the Interlnk files from one computer to another. You must be using a fully pinned serial cable, and the MODE and CTTY commands must be available on the computer where Interlnk is being installed.

Establishing the Interlnk Connection

After you load INTERLNK on the client machine, all you have to do is load INTERSVR on the server machine, and you're in business. When you issue the INTERSVR command on the server, you see a screen similar to the one shown in Figure 8.7.

INTERSVR, activated and waiting for INTERLNK.

Figure 8.7. INTERSVR, activated and waiting for INTERLNK.

Caution

You can use Interlnk for occasional resource sharing. If you constantly interrupt another user's work, however, to use his or her printer, consider investing in a printer-sharing device or installing a small network.

After you have INTERSVR working on the server, return to the client machine and issue the following command:

INTERLNK

This command activates the connection. A message similar to the one shown in Figure 8.8 appears, telling you how you can access the server's resources.

Establishing the Interlnk connection.

Figure 8.8. Establishing the Interlnk connection.

This message tells you that drive A of the remote computer now is available to you as drive D of your local computer, and drive C of the remote computer now is drive E of your local computer.

Using Interlnk to Transfer Files

After you have Interlnk running on both computers, you can use standard DOS commands to gain access to the server's resources.

Using the values shown in Figure 8.8, if you want to see a directory on drive C of the remote computer, type the following command:

DIR E:

To copy files from one computer to the other, issue a COPY (or XCOPY) command, with a drive of one computer as the source and a drive of the other computer as the target. To copy C:SPREADSHUDGET.WQ1 from your local computer to the server, for example, you issue a command such as this:

COPY C: SPREADSH BUDGET.WQ1 E: SPREADSH

Using a Remote Printer

Suppose that your remote computer is connected to a laser printer and your local computer isn't. The status report indicates that LPT1 of your computer is linked to LPT2 of the remote computer. Assuming that the laser printer is attached to LPT2 on that computer, you install your program to print its file to LPT2. Interlnk takes care of redirecting the print job to the server.

Installing Interlnk Remotely

If one of your computers is running DOS 6.22 and the other is running a version of DOS older than DOS 6.0, Interlnk will not be installed. Interlnk can install itself on the remote computer, however, if it is running on the local computer and if the computers are connected via a serial cable using all seven pins. A parallel cable does not suffice. Also, the MODE command must be available on the remote unit. On the local computer, issue the following command:

INTERLNK /RCOPY

You are prompted to select the serial port to be used. After you indicate that port, go to the remote computer and type the following commands:

MODE COMn:2400,N,8,1,P
CTTY COMn:

In these commands, n represents the number of the serial port you are using on the remote computer. This parameter forces the remote computer to accept input from the specified serial port. When you finish typing these commands, return to the computer on which Interlnk is installed and press Enter. Messages on both computers tell you that INTERLNK.EXE and INTERSVR.EXE are being copied. On the receiving computer, the message looks like the following example:

Loading bootstrap

Receiving INTERSVR.EXE (37266) 100%

Receiving INTERLNK.EXE (17133) 100%

The files are placed in the current directory of the receiving computer. Both computers then return to DOS. You can use either computer as the client or the server, provided that you install the device driver in the server's CONFIG.SYS file. If the remote computer is running an early version of DOS, however (3.3 or earlier, for example), you might not be able to access files on the server that were created under a version of DOS later than DOS 5.0, especially if those files are larger than 32MB.

Running Programs Remotely

After you are linked to another computer by Interlnk, you can use that computer's drives as though they were part of your local computer. Thus, you can run a program on the remote computer from the command line as you run one on your local computer.

Because programs on the remote computer do not appear on your local computer's path, you must either log on to the drive and directory where the program resides or enter a PATH command to extend the client's path to a remote directory on the server.

Which technique is appropriate depends on how the program works. If, for example, the program must be run from its home directory when it is not on the path, use the first option. Otherwise, you can use the second technique.

The preceding techniques actually just load the program from the remote computer and run it on your local computer. Consequently, you might encounter problems if the program is set up to use specific aspects of the remote computer's hardware that the local computer lacks. Suppose, for example, that the two computers have different types of screens. The program might be set up to display text and graphics on the remote computer's screen and might be unable to display anything on your local computer.

Another problem occurs if the program expects to find specific files on a particular drive but cannot access the drive because the drive names have been changed. Drive C still is drive C of your local computer, but drive C of the remote computer now is known to DOS as drive E of your local computer. If the program needs to find certain files in drive C, it cannot find those files unless they also exist in the same directory of your local computer. (In such a case, don't run the program from the remote computer; use the version on your local computer instead.)

Case Study: Editing Files with Multiple Data Formats

One problem you commonly encounter when attempting to edit files is multiple data formats. Some files contain a mixture of binary and ASCII data. Almost all modern applications store data and documents in proprietary file formats that contain binary elements. Many of these proprietary formats use a binary header. A header is a block of information at the beginning of a file that is used by a program as a map to the contents of the file.

Editing this type of file with a tool other than the program that created it can be dangerous. You can change the file so that the parent program no longer recognizes the file as being in the proper format.

If you know that a file was created by a specific application, use that application to view and edit the file. The parent application usually has a method of turning data into ASCII format, either with a conversion utility or by a special file save feature built into the application. See your application's documentation for details.

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

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