XCopy

Index

Copies files and directory trees. XCOPY is similar to the COPY command except that it has many more switches that allow considerable control over exactly what is copied when using wildcards..

Syntax:

XCOPY source [destination] [/Switches]

Switches:
sourceThe file(s) to be copied. Although this must be a single parameter, it may include multiple files specified using wildcards (* or ?).
destinationThe location and/or name(s) of new files.
If destination is omitted, the files are copied to the current directory.
If destination refers to a directory that does not exist, the directory is created.
If destination is not an existing directory and could be a file or directory (ie. does not end with a backslash (\)), you are prompted to specify whether destination is a file or directory.
Scope: By default, XCOPY will confine its operation to files in the source directory.
/ECopies the complete subdirectory structure of source and all files therein.
/SCopies the complete subdirectory structure of source and all files therein but does not copy empty subdirectories.
/TCopies the subdirectory structure of source but does not copy any files and does not copy empty subdirectories. To include empty subdirectories, use with the /E switch.
Filters and Attributes: By default: XCOPY will not copy files which have 'system' or 'hidden' attributes set;
copies of 'read-only' files do not have the read-only attribute set, and
all copied files have their 'archive' attribute set. .
/AOnly copies files with the archive attribute set (ie. files that have not been "archived" using xcopy, msbackup, etc.).
/MOnly copies files with the archive attribute set, turning off the archive attribute of the source files.
/HIncludes files with hidden and system attributes set.
/KCopies files without resetting the read-only attribute, if set.
/ROverwrites read-only files.
/UOnly copies files in source that already exist in destination. Can be used with /D to update files with more recent versions. This switch has a bit of a bug - see Note 5 below.
/D:dateOnly copies files with a 'creation date' the same as, or later than, date.
If date is not specified, all files are copied except for same-named files in the destination directory that have a more recent 'creation date' than the one in source.
Note that dates after 2000 must include the full year (01 is read as 1901, not 2001).
The format for date depends on the COUNTRY setting being used. (For US it is mm/dd/yy(yy))
PromptsBy default, XCOPY prompts before overwriting files in destination with files in source of the same name (note: this default can be modified using the COPYCMD environment variable - see SET). XCOPY also prompts for instructions if there is ambiguity whether destination is a directory or file. An ambiguity is seen when destination does not refer to an existing directory or end in a " \ ". Note that a destination of 'name.ext' could be either a file or a directory.
/IForces destination to be treated as a directory. The file/directory prompt is suppressed.
/YOverwrites existing files without prompting.
/-YPrompts before overwriting existing files.(This is the natural default, and overwrites any changes via the COPYCMD environmental variable
/WDisplays a prompt before starting to copy files.
/PPrompts for confirmation before creating each destination file.
/FThe /F switch is specified as "Displays full source and destination file names while copying" but actually does nothing.
/QDoes not display file names or any other messages while copying.
/CContinues copying even if errors occur.
Miscellaneous
/LDisplays files to be copied but does not actually copy them.
/NCopy using the generated short names. This is necessary when copying from a VFAT volume to a FAT volume.
/VVerifies that new files are readable (does not compare with the original - see VERIFY).

Notes:

  1. The /S and /E switches extend the utility of other switches to cover the files in the subdirectories of the source directory.

  2. XCOPY will not copy a folder's attributes (eg. 'hidden'). These have to be set as required using Windows Explorer or ATTRIB.

  3. Xcopy32.exe is a "helper" application that is called by XCOPY as required. Although it can be invoked directly, there is no need to do this and MS advises against it.

  4. The /C (don't stop for errors) switch can be useful when backing up a hard drive that includes the Windows swap file. XCOPY will not copy this file but, without the switch, displays an error message and abandons the copying process. If the switch is included, the swap file is still not copied (it would be of no use in a backup anyway) but the rest of the drive can be copied successfully.

  5. Unfortunately, the /U switch (to only copy files that already exist in the destination directory) has a rather annoying bug in that, when used with the /S switch (to include all subdirectories), the whole subdirectory tree is copied even if no files are found to copy. If trying to update files on a floppy with files scattered over the C: drive, the directory structure could well fill the floppy before actually getting to the files to be copied.

Exit Codes:

0All files were copied without errors
1No files were found to copy
2XCOPY was terminated by Ctrl-C before copying was complete
4An initialization error occurred.
Such an error would generally caused by insufficient memory or disk space, or invalid drive name or syntax).
5 A disk-write error occurred.

Error Messages:

Examples

  1. To copy all files and subdirectories from the data directory to the disk in drive a:
    xcopy c:\data a: /s
    or
    xcopy c:\data\*.* a: /s
  2. To copy all files and subdirectories from the data directory created/modified since 1st Jan.1997 to the disk in drive a: should be:
    xcopy c:\data a: /s /d:1/1/97
  3. To update any files, including those in subdirectories, on the disk in drive a: from everywhere in the data directory on c: should be:
    xcopy c: a: /s /u /d
    but will copy all subdirectories of c: to a: - in many cases not leaving much room for files!

File Details

File NameVersionSizeDateDefault Location
Xcopy.exe Win95: Upgrade3 87811/07/95c:\windows\command
Win95: OSR2.53 87824/08/96c:\windows\command
Xcopy32.exe Win95: Upgrade40 96011/07/95c:\windows\command
Win95: OSR2.541 47224/08/96c:\windows\command

If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
December 9, 1999.