------------------------- MS-DOS v6.22 Help: XCOPY ------------------------- <Notes> <Examples> <Index> ---------------------------------------------------------------------------- XCOPY 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 XCOPY source [destination] [/Y|/-Y] [/A|/M] [/D:date] [/P] [/S] [/E] [/V] [/W] 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. Destination can include a drive letter and colon, a directory name, a filename, or a combination. Switches /Y 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. /-Y 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. /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 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> 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 destination 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. /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) Related Command For information about copying individual files, see the <COPY> command. For information about copying disks, see the <DISKCOPY> command. *** <Syntax> <Examples> ---------------------------------------------------------------------------- XCOPY--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 D if you want the file(s) to be copied to a directory. 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: 0 Files were copied without error. 1 No files were found to copy. 2 The user pressed CTRL+C to terminate XCOPY. 4 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. 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. For more information, see the topic <XCOPY--Examples>. *** <Syntax> <Notes> ---------------------------------------------------------------------------- XCOPY--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:01/18/93 /s /v In this example, only files on the disk in drive A that were written on or after 01/18/93 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 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: @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 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: 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 indicated in the appropriate IF ERRORLEVEL statement. MS-DOS displays the appropriate message and exits from the batch program. *** ---------------------------------------------------------------------------- <Top of page>
Last update: December 07, 2002 14:45 by Content © 1997 Microsoft Corporation All else © 2000-2005 |