File Commands of DOS

DOS allows you to perform certain activities on the files on a disk, such as copying files, deleting them and renaming them. Let us take a closer look at the commands that instruct DOS to carry out these activities.

Copying Files - the COPY Command

If you have a file on the hard disk, you may want to copy it on to a diskette so that you can work with the same data on another machine. Or, you may want a copy of the data that is on a diskette onto the hard disk. Files can be copied from one disk to the other using the COPYcommand. This command also allows you to copy files to a different location on the same disk.

Copying a File to Another Drive under the Same Name

If you wish to copy the files on the hard disk to the diskette, which is in the A drive, the command is

C>COPY C:COMMAND.COM A:COMMAND.COM <Enter>

After the execution of this command, the file COMMAND.COM will exist on the diskette in the A drive, under the same name. After issuing the above command, the screen appears as follows:

C>COPY C:COMMAND.COM A:COMMAND.COM
1 File(s) copied
C>_

DOS displays the following message to indicate to you that the command has been executed:

1 File(s) copied

When using DOS commands, if the file names are not preceded by the drive name, they are assumed to refer to the active drive. Hence, if COMMAND.COM is on the C drive, which is currently active, referring to it as C:COMMAND.COM or COMMAND.COM means the same. But the files from the non-active drive must have the drive name preceding the file name.

If the name of the file is to remain unchanged, the file name need not be specified after the target drive (the drive to which the file is to be copied), which in the example illustrated, is the A drive.

Copying a File to Another Drive under a Different Name

You may want to make some changes in a particular file without losing the original file. If this is the case, you can copy the file on to another disk and work on the copy. You will probably want to give the copied file another name so that you can distinguish between the two files.

You can do this by specifying the new file name after the drive name.

For example, when you issue the command

C>COPY C:SAL.DAT A:SALARY.DAT <Enter>

the file SAL.DAT on the hard disk will be copied on to the diskette under a new name, SALARY.DAT. The contents of both the files will be the same after the file has been copied.

Copying a File as a New File in the Same Drive

Instead of making a copy of SAL.DAT on a diskette, you may want to make a copy on the hard disk itself. You can copy the file in the same drive by issuing the following command:

C>COPY SAL.DAT SALARY.DAT <Enter>

After the execution of this command, you will have the same file under two different names on the same disk.

Copying Files from One Directory to Another

Let us assume that you have created various files under the root directory. You later realize that some of these files are related to each other and you would rather put them together. Therefore, you make a directory to contain these related files. You will recall that issuing the MD command can do this, but this directory is not automatically going to contain the files that you wish to organize under it. However, you do not have to go through the long-drawn process of creating these files again under the new directory. DOS allows you to copy the files from the root directory to the new directory that you have created. For that matter, DOS allows you to copy files from any one directory to another.

Suppose you have a file named SAL.DAT (containing details of salaries of the employees) under the root directory. Since you have already created a new directory called EMPLOYEE and wish to copy the file SAL.DAT to the EMPLOYEE directory, you issue the following command to do that:

C>COPY C:\SAL.DAT C:\EMPLOYEE <Enter>

After issuing this command, the file SALDAT gets copied under the directory EMPLOYEE.

Similarly, you can copy files from one directory to another by specifying the path to DOS. Consider an example where a file NEWMAN.P exists under the directory ACTORS, which is under the directory FAMOUS on the C drive. If you want to copy it to drive A under the NAMES directory under the root, the command is

C>COPY \FAMOUS\ACTORS\NEWMAN.P A:\NAMES <Enter>

After this command is issued, the file NEWMAN.P will exist on the diskette under the NAMES directory.