Copies directories, their subdirectories, and files (except hidden and system files).
With this command, you can copy all the files in a directory, including the files in the subdirectories of that directory.
Syntax
Parameters
Specifies the location and names of the files you want to copy. Source must include either a drive or a path.
Specifies the destination of the files you want to copy. Destination can include a drive letter and colon, a directory name, a filename, or a combination.
Switches
Indicates that you want XCOPY to replace existing file(s) without prompting you for confirmation. By default, if you specify an existing file as the destination file, XCOPY will ask you if you want to overwrite the existing file. (Previous versions of MS-DOS would simply replace the existing file.) If the XCOPY command is part of a batch file, XCOPY will behave as in previous versions. Specifying this switch overrides all defaults and the current setting of the COPYCMD environment variable.
Indicates that you want XCOPY to prompt you for confirmation when replacing an existing file. Specifying this switch overrides all defaults and the current setting of the COPYCMD environment variable.
Copies only source files that have their archive file attributes set. This switch does not modify the archive file attribute of the source file.
For information about how to set the archive file attribute, see the ATTRIB command.
Copies source files that have their archive file attributes set. Unlike the /A switch, the /M switch turns off archive file attributes in the files specified in source.
For information about how to set the archive file attribute, see the ATTRIB command.
Copies only source files modified on or after the specified date. Note that the format of date depends on the COUNTRY setting you are using.
Prompts you to confirm whether you want to create each destination file.
Copies directories and subdirectories, unless they are empty. If you omit this switch, XCOPY works within a single directory.
Copies any subdirectories, even if they are empty.
Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.
Displays the following message and waits for your response before starting to copy files:
Related Command
For information about copying individual files, see the COPY command.
For information about copying disks, see the DISKCOPY command.
Example:
The following example copies all the files and subdirectories (including any empty subdirectories) from the disk in drive A to the disk in drive B:
You can create a batch program to perform XCOPY operations and use the batch IF command to process the exit code in case an error occurs. For example, the following batch program uses replaceable parameters for the XCOPY source and destination parameters:
xcopy %1 %2 /s /e
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit
:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
:exit
To use this batch program to copy all files in the C:\PRGMCODE directory and its subdirectories to drive B, type the following command:
Notes:
Default value for destination
If you omit destination, the XCOPY command copies the files to the current directory.
Specifying whether destination is a file or directory
If destination does not contain an existing directory and does not end with a backslash (\), XCOPY prompts you with a message in the following format:
Setting the COPYCMD environment variable
You can set the COPYCMD environment variable to specify whether you want the COPY, MOVE, and XCOPY commands to prompt you for confirmation before overwriting a file in all cases, whether issued from the command prompt or from a batch file.
To force the COPY, MOVE, and XCOPY commands to prompt you before overwriting in all cases, set the COPYCMD environment variable /-Y. To force these commands to overwrite in all cases without prompting you, set the COPYCMD environment variable to /Y.
Typing any of these commands with the /Y or /-Y switch overrides all defaults and the current setting of the COPYCMD environment variable.
XCOPY does not copy hidden and system files
In older versions of MS-DOS, XCOPY copied hidden and system files. This is not the case in MS-DOS 6.22. To remove the hidden or system attribute from a file, use the ATTRIB command.
XCOPY sets archive attribute for destination files
XCOPY creates files with the archive attribute set, whether or not this attribute was set in the source file. For more information about file attributes, see the ATTRIB command.
XCOPY vs. DISKCOPY
If you have a disk that contains files in subdirectories and you want to copy it to a disk that has a different format, you should use the XCOPY command instead of DISKCOPY. Since the DISKCOPY command copies disks track by track, it requires that your source and destination disks have the same format.
XCOPY has no such requirement. In general, use XCOPY unless you need a complete disk image copy. However, XCOPY will not copy hidden or system files such as IO.SYS and MSDOS.SYS. Therefore, use DISKCOPY to make copies of system disks.
XCOPY exit codes The following list shows each exit code and a brief description of its meaning:
Files were copied without error.
No files were found to copy.
The user pressed CTRL+C to terminate XCOPY.
Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
Disk write error occurred.