xcopy(CMD) 19 June 1992 xcopy(CMD) Name xcopy - copy files and directories, including subdirectories Syntax xcopy source [destination] [/a|/m] [/d:date] [/p] [/s [/e]] [/v] [/w] Description With this command, you can copy all the files in a directory, including the files in the subdirectories of that directory. Parameters source Specifies the location and names of the files you want to copy. source must include either a drive or a path. destination Specifies the destination of the files you want to copy. desti- nation can include a drive letter and colon, a directory name, a filename, or a combination. Switches /a 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(CMD) command. /m 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(CMD) command. /d:date 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. /p Prompts you to confirm whether you want to create each destina- tion file. /s Copies directories and subdirectories, unless they are empty. If you omit this switch, xcopy works within a single directory. /e Copies any subdirectories, even if they are empty. You must use the /s switch with this switch. /v Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files. /w Displays the following message and waits for your response before starting to copy files. Press any key to begin copying file(s) 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: Does destination specify a file name or directory name on the target (F = file, D = directory)? Press F if you want the file(s) to be copied to a file. Press P if you want the file(s) to be copied to a directory. xcopy does not copy hidden and system files In previous versions of MS-DOS, xcopy copies hidden and system files. This is no longer the case in MS-DOS version 5.0. To remove the hidden or system attribute from a file, use the attrib command. xcopy sets archive attribute for destination files copy 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(CMD) 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. copy 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: 0 Files were copied without error. 1 No files were found to copy. 2 The user pressed CtrlC to terminate xcopy. 4 Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syn- tax on the command line. 5 Disk write error occurred. You can use the errorlevel parameter on the if command line in a batch program to process exit codes returned by xcopy. See the following ``Examples'' section. Examples 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: xcopy a: b: /s /e The following example uses the d and v switches: xcopy a: b: /d:04/11/90 /v In this example, only files on the disk in drive A that were written on or after 04/11/90 are copied to the disk in drive B. Once the files are written to the disk in drive B, the xcopy command compares the files on the two disks to make sure they are the same. You can create a batch program to perform xcopy operations and use the batch if command to pro- cess the exit code in case an error occurs. For example, the following batch program uses replaceable parameters for the xcopy source and desti- nation parameters: @@echo off rem COPYIT.BAT transfers all source rem files in all directories on the source rem drive (%1) to the destination drive (%2) 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 CtrlC 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: copyit c:\prgmcode b: The command interpreter substitutes C:\PRGMCODE for %1 and B: for %2, then uses xcopy with the /e and /s switches. If xcopy encounters an error, the batch program reads the exit code and goes to the label indi- cated in the appropriate if errorlevel statement. MS-DOS displays the appropriate message and exits from the batch program. Related command For information about copying individual files, see the copy(CMD) com- mand.