Xcopy Command Windows 10: How to Copy Files and Folders
In this article
The Xcopy command in Windows 10 is a powerful command-line utility used to copy multiple files, including entire directory trees, from one location to another. Unlike the standard copy command, which only handles individual files, Xcopy allows you to duplicate folders, subfolders, and the files contained within them while maintaining the original folder structure. To use it, you simply open the Command Prompt and enter the command followed by the source path and the destination path.
What You'll Need
- A computer running Windows 10.
- Administrative privileges (required if you are copying files into protected system folders like Program Files or Windows).
- The exact file paths for your source and destination folders.
- Access to the Command Prompt (CMD).
Step-by-Step
- Open the Command Prompt: Click the Start button, type "cmd" into the search bar, and press Enter. If you intend to copy files to a system-protected area, right-click "Command Prompt" in the search results and select "Run as administrator."
- Identify Your Source Path: Locate the folder you want to copy. For example, if your files are in a folder called "Work" on your D drive, your source path is
D:\Work. If there are spaces in the folder name (e.g.,D:\My Work), you must enclose the path in double quotation marks. - Identify Your Destination Path: Decide where the files should go. For example, if you are backing up to an external drive labeled E, your destination path might be
E:\Backup. Again, use quotation marks if the path contains spaces. - Construct the Basic Command: The basic syntax for Xcopy is . For a simple copy of files from one folder to another, you would type: xcopy D:\Work E:\Backup and press Enter.
- Add Switches for Folders and Subfolders: By default, Xcopy only copies files in the root of the source folder. To copy all subfolders and the files within them, you must add the
/Sswitch. To copy all subfolders, including empty ones, use the/Eswitch. Example:xcopy D:\Work E:\Backup /E - Preserve File Attributes: If you want to ensure that the destination files keep their original attributes (such as read-only or hidden status), add the
/Iswitch if the destination does not exist. This tells Windows that the destination is a directory rather than a single file. Example:xcopy D:\Work E:\Backup /E /I - Execute the Command: Once you have typed your full string (e.g.,
xcopy "C:\Users\Name\Documents" "D:\Backup\Documents" /E /I /H), press Enter. You will see a list of files being copied in the terminal window. - Verify the Transfer: Once the process is complete, open File Explorer and navigate to the destination path to ensure all folders and files have been transferred correctly.
Common Mistakes
One of the most frequent errors is forgetting to use quotation marks around paths that contain spaces. For example, xcopy C:\My Documents D:\Backup will fail because the command interprets the space after "My" as the end of the source path and the start of the destination path. Always use "C:\My Documents" to avoid this.
Another common mistake is using the /S switch when you actually need the /E switch. While /S copies subdirectories, it ignores any folder that is completely empty. If your project relies on a specific folder structure where empty directories are necessary for the software to function, omitting the /E switch will result in a broken directory tree at the destination.
Users also frequently forget to run the Command Prompt as an administrator. If you attempt to copy files from a user directory into a system directory (like C:\Windows or C:\Program Files), Windows will return an "Access Denied" error. This is a security feature designed to prevent unauthorized changes to the OS.
Finally, confusing Xcopy with Robocopy is common. While Xcopy is great for basic tasks, it lacks the advanced mirroring and resume capabilities of Robocopy. Attempting to use Xcopy for massive multi-terabyte migrations can be slower and less reliable than using the newer Robocopy utility.
Tips
To speed up the process and avoid being prompted for every single file, use the /Y switch. This suppresses the prompt that asks if you want to overwrite an existing file in the destination folder. This is essential for automated scripts or large backups where you know you want the newest version of the file to replace the old one.
If you only want to copy files that have changed since the last backup, use the /D switch. This tells Xcopy to copy only those files whose source time is newer than the destination time. This significantly reduces the time required for subsequent backups of the same folder.
To copy hidden and system files, you must include the /H switch. By default, Xcopy ignores files marked as hidden or system files. If you are backing up a full drive or a configuration folder, omitting /H will result in an incomplete copy.
For those creating a batch file (.bat) to automate their backups, combining these switches is the most efficient method. A typical professional backup string looks like this: xcopy "C:\Source" "D:\Destination" /E /H /C /I /Y. The /C switch is particularly useful here as it tells Xcopy to continue copying even if an error occurs with a specific file, ensuring the rest of the backup completes.
Troubleshooting
If you receive an "Invalid drive specification" error, double-check that the drive letter you entered is correct and that the external drive is properly plugged into the USB port. If the drive is not showing up in File Explorer, the Command Prompt will not be able to find it.
If the command asks "Does [Destination] specify a file name or directory name on the target?", it means Xcopy isn't sure if you want to create a new folder or rename the copied files into one large file. To fix this, either type "D" for directory or, better yet, add the /I switch to your command to tell Windows the destination is always a folder.
When encountering "Access Denied" errors despite being an administrator, check the permissions of the source folder. Right-click the folder in File Explorer, go to Properties > Security, and ensure your user account has "Read" permissions for that specific folder. If the files are owned by another user or a system service, you may need to take ownership of the folder before Xcopy can access them.
If the copy process hangs or stops unexpectedly, check for "file in use" errors. Xcopy cannot copy a file that is currently open and locked by another program (such as an open Word document or a running database). Close all open applications and try the command again.
Frequently Asked Questions
What is the difference between Copy and Xcopy?
The standard copy command is designed for individual files or groups of files in a single folder. Xcopy (Extended Copy) can copy entire directory structures, including subfolders and their contents, which the basic copy command cannot do.
Can Xcopy be used to move files instead of copying them?
No, Xcopy is strictly for copying. To move files and folders via the command line, you should use the move command or the robocopy /move switch.
Does Xcopy delete files in the destination folder?
No, Xcopy does not delete files. It only adds new files or overwrites existing ones if instructed. If you want the destination to be an exact mirror of the source (meaning files deleted in the source are also deleted in the destination), you must use Robocopy with the /MIR switch.
How do I copy only specific file types with Xcopy?
You can use wildcards to specify file types. For example, to copy only PDF files from one folder to another, use xcopy C:\Source\*.pdf D:\Destination. The asterisk (*) acts as a placeholder for any filename.
Is Xcopy still supported in Windows 10?
Yes, Xcopy is still available in Windows 10 for backward compatibility and simple scripting, although Microsoft generally recommends Robocopy for more complex or large-scale data migrations.
Can Xcopy copy files over a network?
Yes, as long as the network drive is mapped to a letter (like Z:) or you use the UNC path (e.g., \\Server\Share) enclosed in quotation marks.