With its many options and ability to copy entire directories, it’s similar to, but much more powerful than, the copy command. The robocopy command is also similar but has even more options.
Xcopy Command Availability
This command is available from within the Command Prompt in all Windows operating systems including Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows 98, etc. You can also access the command in MS-DOS as a DOS command.
Xcopy Command Syntax
Use the following syntax for the xcopy command: xcopy source [destination] [/a] [/b] [/c] [/d [:date]] [/e] [/f] [/g] [/h] [/i] [/j] [/k] [/l] [/m] [/n] [/o] [/p] [/q] [/r] [/s] [/t] [/u] [/v] [/w] [/x] [/y] [/-y] [/z] [/exclude:file1[+file2][+file3]…] [/?]
Copy Files to a New Folder
In the above example, the files contained in the source directory of C:\Files are copied to destination, a new directory [/i] on the E drive called Files. No subdirectories, nor any files contained within them, will be copied because the /s option was not used.
Xcopy Backup Script
In this example, xcopy is designed to function as a backup solution. Try this if you’d like to use xcopy instead of a backup software program to back up your files. Put the command as shown above in a script and schedule it to run nightly. As shown above, the command is used to copy all the files and folders [/s] newer than those already copied [/d], including empty folders [/e] and hidden files [/h], from source of C:\Important Files to the destination of D:\Backup, which is a directory [/i]. We have some read-only files we want to keep updated in destination [/r] and we want to keep that attribute after being copied [/k]. We also want to make sure we maintain any ownership and audit settings in the files we’re copying [/x]. Finally, since we’re running xcopy in a script, we don’t need to see any information about the files as they’re copied [/q], We don’t want to be prompted to overwrite each one [/y], nor do we want the command to stop if it runs into an error [/c].
Copy Files and Folders Over the Network
Here, the command is used to copy all the files, subfolders, and files contained in the subfolders [/s] from source of C:\Videos to the destination folder Media Backup located on a computer on the network by the name of SERVER. We’re copying some really large video files, so buffering should be disabled to improve the copy process [/j], and since we’re copying over the network, we want to be able to resume copying if we lose the network connection [/z]. Being paranoid, we want to be prompted to start the process before it actually does anything [/w], and we also want to see every detail about what files are being copied as they’re being copied [/f].
Duplicate Folder Structure
In this final example, we have a source full of well-organized files and folders in C:\Client032 for a client. We’ve already created an empty destination folder, Client033, for a new client but we don’t want any files copied—just the empty folder structure [/t] so that we’re organized and prepared. We have some empty folders in C:\Client032 that might apply to the new client, so we want to make sure those are copied as well [/e].
Xcopy & Xcopy32
In Windows 98 and Windows 95, two versions of the xcopy command were available: xcopy and xcopy32. However, the latter command was never intended to be run directly. When you execute xcopy in Windows 95 or 98, either the original 16-bit version is automatically executed (when in MS-DOS mode) or the newer 32-bit version is automatically executed (when in Windows). To be clear, no matter what version of Windows or MS-DOS you have, always run the xcopy command, not xcopy32, even if it’s available. When you execute xcopy, you’re always running the most appropriate version of the command.
Xcopy Related Commands
The xcopy command is similar in many ways to the copy command but with significantly more options, like the ability to copy folders, copy every file in subdirectories, and exclude files. This command is also very much like the robocopy command except that robocopy has more flexibility than even xcopy. The dir command is often used with xcopy to check which folders and files are in a directory before completing the command.