New to using the command prompt? Check out the Windows Command Prompt Beginner’s Guide
If you are looking to transfer lots of files, large files, a large amount of data, or a combination of the above, you should consider using Xcopy—a command line tool used to copy data.
In this guide, we’ll take a look at:
- The basic syntax of Xcopy.
- How to use parameters to refine Xcopy behavior.
- How to output Xcopy results to a text file.
I decided to write this guide after using Xcopy to transfer 1.2 TB of data from one drive to another after the first drive started failing on me. The advantage of using Xcopy is that you can automate responses to questions like (Do you want to overwrite this file) and also continue the copy process should you hit bad sectors on the drive (ordinarily this would either kill the copy process—in Windows XP—or ask you to Cancel the process or skip the file—Windows 7/Vista.)
Xcopy is a powerful tool and I hope to explain it in simple terms in this guide.
The Basic Syntax of Xcopy
To run Xcopy, open a command prompt (how do I run a command prompt?)
Type xcopy followed by the source location (red) and the destination location (orange)
i.e. xcopy g:\ u:\ will copy everything from the G drive to the U drive.
How to Use Parameters to Refine Xcopy Behavior
Parameters can be used to refine the copying process. These parameters (blue) are added after the source and destination folders to apply certain rules; below is an explanation of the ones I use the most (“cherkys”):
- /c : Ignores errors.
- /h : Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
- /e : Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.
- /r : Copies read-only files.
- /k : Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.
- /y : Suppresses prompting to confirm that you want to overwrite an existing destination file.
- /s : Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.
For more parameters, see the Microsoft Help page.
How to Output Xcopy Results to a Text File
If you want to create a text file with the results of the xcopy process (to check for any errors), you can add a parameter to create the text file (just like most commands.) Simply add >>out.txt (green) to the command (which will save the text file to the currently selected directory—in this case it’s C:\Users\Rich)
Want to learn more about Xcopy? Check this Microsoft Help page.