Classic Computer Magazine Archive COMPUTE! ISSUE 125 / JANUARY 1991 / PAGE PC18

Need to move data? XCOPY to the rescue. (Introdos) (column)
by Tony Roberts


One of the hidden jewels in DOS versions 3.2 and higher is the XCOPY command. XCOPY is a clear improvement over COPY, but many users ignore it, probably for two reasons. First, COPY is easy, convenient, and already learned; second, one look at the XCOPY page in any DOS manual can scare even DOS aficionados. You have a choice of eight possible switches, and it's hard to know where to begin. Why use XCOPY? It's faster, more powerful, and smarter.

In moving data from a hard disk to a floppy or vice versa, XCOPY reduces the transaction time by about 20 percent. The saving comes because COPY reads and writes each file individually, but XCOPY reads as many files into memory as it can and then writes out the whole group at once.

XCOPY also eliminates the pain of copying files in subdirectories from one disk to another. The command XCOPY A:*.* B:/S copies all the files in the current directory and its subdirectories on drive A to drive B, creating any necessary subdirectories as it goes. If you add/E, empty subdirectories on the source disk will be created on the target disk as well.

If you carry disks with work in progress from your office to your home, XCOPY can help make sure you have the latest versions of the files you need wherever you are. One way to do this is by using the /D, or date, switch. This tells XCOPY to copy only those files that were changed on or after a certain date.

Let's say you're working on a proposal that consists of several data files. The files you're working on are all in the same subdirectory, and all have the extension DAT.

The command XCOPY C:*.DAT A: /D:mm/dd/yy (substituting the current date for mm/dd/yy) copies all the DAT files that were modified today to the disk in drive A. Once you arrive home, switch to the subdirectory that holds your data files and reverse the procedure with the command XCOPY A: C: /D:mm/dd/yy. When you've finished work for the evening, use the first command again to update the data files on the disk; then tomorrow morning use the second command to update the files on the hard disk at work.

Using the date switch works well unless there are too many files to fit on one disk. If that's the case, let XCOPY copy files based on the status of the archive bit.

The archive bit is a piece of information DOS keeps about every file. It's a simple on/off switch. If it's on, the file has been changed since the last backup. If it's off, no changes to the file have occurred.

Later versions of DOS include a command, ATTRIB, that allows you to change the file status bits, which, besides archive, include read-only, hidden, and system file attributes. Most disk utility programs also have ATTRIB commands, and their versions are usually more powerful and easier to use than their DOS counterparts.

Let's say you want to keep daily backups of the files in your word processing subdirectory. Switch to that subdirectory; then use the command ATTRIB-A to turn off the archive bit in each of the files.

Now, as you create new files or modify existing ones, the archive bits for those files will be turned on. At day's end, you can use XCOPY with the /M switch to copy only those files that have been changed. The command would be XCOPY C: A: /M.

XCOPY will begin copying changed files from the current subdirectory to the disk on drive A. At the same time, it will turn off the archive bit for each of the files it successfully copies. If you have several files to copy, the disk in drive A will eventually get too full hold more information and XCOPY will stop work and display an error message indicating that the disk is full.

When this happens, insert another disk and repeat the XCOPY. The files that were copied to the first disk won't be copied again because their archive bit is no longer on. Repeat the process until all the files you want to back up have been copied.

If you're interested in automating this daily backup process, you could set up a batch file that would copy the files from several subdirectories. To make such a batch file work successfully, though, you'd have to know whether all the files in one subdirectory were successfully copied before going on.

The ERRORLEVEL command from DOS's batch programming language could be used for this task. If XCOPY exits without completing its task, it sets an ERRORLEVEL code. Your batch program can test for that condition, and if it occurs, you can prompt the user to insert a new disk and then have the batch file repeat the previous command to copy the remaining files to the floppy.

Four of the eight XCOPY switches have been mentioned. The others are less used but could come in handy for certain applications. Check out XCOPY in your DOS manual and see if this powerful command's other options are useful to you.