The magazine of the Melbourne PC User Group

Copy (Con)Cat(enation)
Tom Coleman

Probably one of the first things we learn to do on a computer is to copy a file. At first this looks like the only use for the COPY command and the only way to make a copy. Later we realise that there is a whole world of copying out there with more nooks and crannies than we had ever imagined. Lets take a look at a few.

First: some ground rules.
  • I am going to assume that the various files mentioned are always available. That means they may be in the PATH or in the current directory.
  • I am also going to assume that you know enough about computing to be aware where these various discussions fit into the overall scene.
  • Last of all I am going to assume that you know enough about command line computing to understand what a command is and that some commands have switches and parameters. In other words if all you ever see is a menu or Xtree or Windows you are going to wonder just what the hell I am on about.
The COPY command is an internal command. It comes built-in to Command.Com and gets loaded up when Command.Com loads. You don't have to do anything - it is available by virtue of the computer being turned on.

I am not discussing XCOPY or DISKCOPY; they are a different kettle of fish. Generally this discussion does not apply to them.

The COPY  command accepts a source, a target and a couple of parameters thus :-
Command Source Target Parameters
Copy C:\data\*.*  A:   /A or /B and /V

If you do not specify a target then it will copied to the current directory.

You cannot copy a file to the same directory as the source without making a name change. I will come back to this shortly.

If you do not supply a path in the source then files are copied from the current directory.

Here is a minor diversion. Ordinary ASCII text files only have an End of File marker (Ctrl Z) at the end. However program files and binary files in general may have them littered through with wild abandon.

An effect of the ^Z may be to end the copy operation as soon as the command reaches the first ^Z. This could severely limit the usefulness of the copy command so the default is to ignore all ^Zs. This is what /B does so you generally don't have to specify it if you are doing a simple file copy.

The /A treats the file as an ASCII file and stops reading the file at the first ^Z. It then adds a ^Z to the end of the completed copy.

You can join two ASCII files together or append one to the other. Same thing, different words. This is how it is done.

Command Source Target
Copy Filel.Ext+File2.Ext File3.Ext

This appends File2 to File1 and calls the new file FIle3. If I had not nominated the target as File3 then the target file would be File1 which would grossly modify the original File1 and I would lose the original. File2 would not be changed as it is only copied.

This where it gets tricky. When concatenating, (Oh what a lovely word - It means joining files with the + between them) the files are treated as ASCII files and you are in trouble with any embedded ^Zs So the /B may be prudent.

The /V is almost useless. The checks to see if what has been written is readable. It does not check the validity of the copy by comparison to the original. For the most part it only slows things down. Back in the old days when disk surface media was less reliable it may have had a place in the over all scheme of things.

If you are not in a hurry or you have doubts about your disk then there is a fraction more security using /V.

Another use for the COPY command comes when you want two copies of a file in the same directory. You must change the name because you can't have two files with the same name in the same directory.

To make a copy with a name change you just:-

Command Source Target
COPY CUCKOO.BAT OSTRICH.BAT

Now you have two identical files with different names.

Of course if you did not want to retain a copy with the original name then you could have simply renamed it. Thus:

REN CUCKOO.BAT OSTRICH.BAT

but then you would not have a file called CUCKOO.BAT.

Another diversion. You should not have .COM .EXE or .BAT files sharing the same filename in the same directory either. This is because DOS searches for these files in that order by their filename and as soon as it finds one it stops looking. This means that if you had CUCKOO.COM and CUCKOO.BAT in the same directory the .BAT file would never get executed because the .COM file would always be found first.

More diversions. These commands are fairly well spaced. You must put at least one space between the various parts of the command but you can put 20 spaces if you like. DOS ignores multiple space.

For the most part there is no difference between the COPY command and the XCOPY command when you are copying a single file. However as soon as there is more than one file to copy, XCOPY will do the job faster because it reads all it can fit into available memory and then writes it all at once.

However if you have some problem files that are giving a DATA READ error, you may be better off using the COPY command.

If anything goes wrong with any part of the XCOPY command it gets the sulks and aborts the whole copy operation. The COPY command may get a little fidgety and toss up the odd error message but if it fails it just goes on the next file, so that you only miss the problem files. In some cases copy will read and write a file that XCOPY does not like.

The next use for the copy command is so discouraging that I am not sure that it should be mentioned. It is the dreaded COPY CON.

I think we are having more diversions than substance in this article. Here we go again.

CON is a reserved word that DOS uses to refer to the STANDARD INPUT (Jargonese for Keyboard) and STANDARD OUTPUT (More jargonese for Monitor).

COPY CON is great for knocking out quick little text or .BAT files.

So:
COPY CON Filename.Ext

Will create a file named FILENAME.EXT in the current directory. You can put a complete filespec in if you wish.

Each time you press ENTER the cursor advances a line. Your Prompt has disappeared and (Horrors) you can't get back up to the line above. You can only edit the current line. If you are not confidently error free with you input you will soon find that three or four lines is all that you can stand.

When you have entered all the lines, you press ENTER so that the cursor is on a blank line and either press F6 or hold down the Ctrl key and tap Z, then press ENTER. Either way a ^Z (we were talking about that just before) is printed and then you get your prompt back.

If you now type DIR you will see that the file has been created.

Now here is a little diversion you can try out for yourself

COPY FILENAME.EXT PRN

does the same as

TYPE FILENAME.EXT >PRN

which can be interesting if you misplace the redirection (the >).

Have a go. It won't do anything drastic.

PRINT FILENAME.EXT

is more of the same but relies on the external PRINT.COM file being available. The main advantage here being the spooling built in to the PRINT command. You get your prompt back and can be doing something else while a document prints out.

COM and TYPE lock up the computer until the job is done. They are best suited to short jobs and PRINT for the longer ones.

There is a lot more to the PRINT command. It is worth looking into.

Reprinted from the July 1992 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]