Copying Files and Directories - the XCOPY Command

If you have a disk that contains files in subdirectories, and you want to copy the directories and subdirectories too, the XCOPY command should be used.

You could also use the COPY command globally, but this would copy the files of only the working directory and not subdirectories and its files.

The DISKCOPY command may also be used. However, the disadvantage is that it formats the disk, and copies the entire contents of one disk to another. You may, perhaps, not want to lose the existing contents of the target diskette. Also, you may not want to copy the entire contents of the source disk.

The XCOPY command has a major advantage over the other commands to copy files, because this command offers two special options. One of these options prompts you to specify the files that you wish to copy, and the other copies the directories and lower level directories. Besides, unlike DISKCOPY, XCOPY can be used to copy files from the hard disk too.

If you do not wish to copy every file on the disk, you may use the /P option with the XCOPY command.

For example, if you issue the command:


DOS will prompt you with (Y/N), allowing you to confirm whether you want to copy each target file.

If you wish to copy the directories and lower level directories, DOS offers you another option with the XCOPY command. In this case you may use the /S option.

The command you could issue is:


This command will copy the directory REPORT and all its subdirectories, unless they are empty.

If you do not specify /S with the XCOPY command, it works within a single directory.

Both the options can be specified in a single command. For example,


You are advised to include the path and file name with the XCOPY command; XCOPY assumes that the operations are to be carried out in the currently active directory.

The program file XCOPY.EXE must exist in order to execute this command.