|
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:
| source | The file(s) to be copied. Although this must be a single parameter, it may include multiple files specified using wildcards (* or ?). |
| destination | The 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. |
| /E | Copies the complete subdirectory structure of source and all files therein. |
| /S | Copies the complete subdirectory structure of source and all files therein but does not copy empty subdirectories. |
| /T | Copies 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. . |
| /A | Only copies files with the archive attribute set (ie. files that have not been "archived" using xcopy, msbackup, etc.). |
| /M | Only copies files with the archive attribute set, turning off the archive attribute of the source files. |
| /H | Includes files with hidden and system attributes set. |
| /K | Copies files without resetting the read-only attribute, if set. |
| /R | Overwrites read-only files. |
| /U | Only 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:date | Only copies files with a 'last modified 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 'last modified 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))
|
| Prompts | By 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. |
| /I | Forces destination to be treated as a directory. The file/directory prompt is suppressed. |
| /Y | Overwrites existing files without prompting. |
| /-Y | Prompts before overwriting existing files.(This is the natural default, and overwrites any changes via the COPYCMD environmental variable |
| /W | Displays a prompt before starting to copy files. |
| /P | Prompts for confirmation before creating each destination file. |
| /F | The /F switch is specified as "Displays full source and destination file names while copying" but actually does nothing. |
| /Q | Does not display file names or any other messages while copying. |
| /C | Continues copying even if errors occur.
|
| Miscellaneous |
| /L | Displays files to be copied but does not actually copy them. |
| /N | Copy using the generated short names. This is necessary when copying from a VFAT volume to a FAT volume. |
| /V | Verifies that new files are readable (does not compare with the original - see VERIFY). |
Notes:
- The /S and /E switches extend the utility of other switches to cover the files in the subdirectories of the source directory.
- XCOPY will not copy a folder's attributes (eg. 'hidden'). These have to be set as required using Windows Explorer or ATTRIB.
- 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 (but see Caveat below).
- 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.
-
In the transition from Dos 6.x to Dos 7.x, XCOPY has been significantly enhanced. For reasons I do not understand, in Win 95 (all versions) the new program was not simply named "xcopy.exe" but "xcopy32.exe" and xcopy.exe became simply a pointer to xcopy32.exe. Xcopy32.exe could be invoked directly and would run just fine on its own.
In spite of MS urging to NOT use the XCOPY32 command (rather than sticking with XCOPY) there have been persistant - totally inaccurate - reports in the newsgroups to the effect that using XCOPY32 will work with long filenames when working in a boot-to-Dos environment.
Perhaps in an effort to forestall this apparently harmless practice, in Win98 MS renamed the main file "xcopy32.mod" which is called automatically by both XCOPY and XCOPY32.
In Win98, xcopy.exe and xcopy32.exe are identical and both simply point to xcopy32.mod. Actually, although I certainly don't advocate the practice, it seems that everything works just fine if xcopy.exe and xcopy32.exe are deleted and xcopy32.mod is renamed as xcopy.exe.
If anyone understands the background/reasons for this name dancing, I would be most appreciative of their advice!
Exit Codes:
| 0 | All files were copied without errors |
| 1 | No files were found to copy |
| 2 | XCOPY was terminated by Ctrl-C before copying was complete |
| 4 | An 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. |
Caveat
Whilst XCOPY is usually perfectly sufficient for copying the contents of one disk to another and making backups, it cannot be considered 100% reliable. The problem arises because the relationship between long and short filenames is not necessarily the same in both original and copy and this can cause problems if a program calls a file by its short name.
Although this sounds like a serious flaw in the whole long/short filename concept and it is not difficult to demonstrate the potential diffuculties, the fact is that in real life it is seldom that all the conditions for trouble are met simultaneously.
To be specific, these conditions are:
- A program or file must be called with its short filename and/or the path must include a short name.
- There must be at least two versions of the short name.
- At some time, one version of the short name (but not the latest) on the source must have been deleted.
This problem is discussed in some detail (and with evangelical zeal) at PCGuide - Articles - Xcopy Xposed by Charles M. Kozierok and How do I clone/backup a hard disk under Windows? by John Navas.
Examples
- 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
- 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
- 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 Name | Default Location | Dos Ver. | Win Ver. | Size | Date | Source |
| Xcopy.exe | c:\windows\command |
7.0 | Win95 |
3 8781 | 11/07/95 | win95_09.cab |
| 7.1 | Win95 (OSR2.x) |
3 8782 | 24/08/96 | win95_14.cab |
| Win98 |
3 8783 | 11/05/98 | win98_43.cab |
| Win98 SE |
3 8783 | 23/04/99 | win98_47.cab |
| Xcopy32.exe | c:\windows\command |
7.0 | Win95 |
40 960 | 11/07/95 | win95_09.cab |
| 7.1 | Win95 (OSR2.x) |
41 4724 | 24/08/96 | win95_14.cab |
| Win98 |
3 8783 | 11/05/98 | win98_43.cab |
| Win98 SE |
3 8783 | 23/04/99 | win98_47.cab |
| Xcopy32.mod | c:\windows\command |
7.1 | Win98 |
41 4725 | 11/05/98 | win98_45.cab |
| Win98 SE |
41 4726 | 23/04/99 | win98_51.cab |
Superscripts denote which same size files, if any, are identical (using FC).
|