Xcopy is the classic Windows command-line tool for copying files and entire folder trees, and its power comes from its switches: short flags like /s, /e, /i and /h that change what gets copied and how. The shortest working recipe is xcopy "C:\Source" "D:\Backup" /e /i /h /y, which copies every subfolder (including empty ones), treats the destination as a folder, includes hidden and system files, and overwrites without prompting. Run it from Command Prompt or PowerShell, one line at a time, and test on a small folder first.
Xcopy still ships with current Windows versions, though Microsoft has long recommended robocopy for large or robust jobs. Xcopy remains useful because it is simple, scriptable and available everywhere. The trick is knowing which switches you actually need and which combinations quietly change behaviour.
What You'll Need
- A Windows PC with Command Prompt or PowerShell (xcopy is built in; nothing to install).
- The exact source path, quoted if it contains spaces.
- A destination folder, ideally on a different drive so you can verify the copy.
- Administrator rights if you are copying system files, protected folders, or writing into Program Files.
- A test folder with a few files and one empty subfolder so you can see each switch's effect.
Step-by-Step
- Open a command prompt. Press the Windows key, type cmd, and choose Run as administrator if you need elevated access. In PowerShell, xcopy works the same way. Note that menu labels and prompts can differ slightly by Windows version and region.
- Check the help first. Type xcopy /? and press Enter. This prints the full switch list for your exact build, which is more trustworthy than any guide because switches have stayed stable for years but help text varies.
- Test where you are. Run echo %cd% to see the current folder, and use cd /d "C:\Source" to move there. Relative paths are resolved from this folder, so being in the wrong place is the most common reason a command looks like it did nothing.
- Build the basic copy first. Start with xcopy "C:\Source" "D:\Backup" /s. The /s switch copies subfolders but skips empty ones. Confirm the files arrive before adding more switches.
- Add /e to include empty folders. /e copies all subfolders, empty or not, and implies /s. Use it for backups where folder structure matters. Use plain /s when you only care about files.
- Add /i when the destination does not exist yet. Without /i, xcopy asks whether the destination is a file or a folder unless you are copying multiple files. /i tells it to assume a directory and suppresses the prompt, which matters in scripts where nobody can answer.
- Decide on hidden and system files with /h. By default xcopy skips hidden and system files. Add /h to include them, and add /r as well if you need to overwrite read-only files. This is essential for true full backups and irrelevant for ordinary documents.
- Control overwrite prompts with /y or /y /-y. /y suppresses the overwrite confirmation, which you want in scheduled scripts. To force prompts even when a COPYCMD environment variable would suppress them, use /-y. Pick one deliberately; silent overwrites can destroy newer destination files.
- Choose copy semantics: /d, /u or /m. /d copies only files whose source version is newer than the destination, good for incremental refreshes. /u copies only files that already exist in the destination. /m copies archive-attribute files and clears the archive bit on the source, while /a copies them without clearing it. Avoid /m unless you understand the archive attribute; it changes your source files.
- Keep timestamps and attributes with /k and /o. By default xcopy resets the read-only attribute. Add /k to retain attributes and /o to retain ownership and access control lists. Use /o only when running with the rights needed to preserve permissions.
- Verify the copy with /v and read the summary. /v verifies each new file, which slows the job but catches write errors. At the end xcopy reports files copied and files failed. Treat any failure count above zero as a stop sign.
- Turn the working command into a script. Put the tested line in a .bat or .cmd file with quoted paths, log output with >> copy.log 2>&1, and schedule it with Task Scheduler if it needs to run regularly. Only add switches you have already tested by hand.
- Compare with robocopy before committing. If the job is large, crosses a network, or needs mirroring and retry logic, use robocopy instead. It handles long paths, restarts and multithreading better. Xcopy is best for straightforward folder copies and legacy scripts.
Common Mistakes
- Forgetting /i in unattended scripts, so xcopy stops at a directory-or-file prompt.
- Using /e but forgetting /h, then wondering why hidden files are missing from a backup.
- Leaving out /y and having a script hang on the overwrite question, or including it blindly and overwriting newer files.
- Unquoted paths with spaces, which xcopy reads as separate arguments. Always wrap paths in double quotes.
- Using /m and accidentally clearing the archive attribute on source files, which breaks other backup tools that rely on it.
- Assuming xcopy copies open or locked files; it does not. Files in use may be skipped, and the summary will show failures.
- Mixing up /a and /m; only one of them changes the source, and it is /m.
Tips
- Always dry-run on a small test folder with the same switches before pointing at a real drive.
- Combine switches in one argument string at the end of the command; order among switches does not matter.
- Log every run: xcopy ... /y >> "%USERPROFILE%\copy.log" 2>&1 gives you a trail when something fails overnight.
- If paths are very long, xcopy can hit path-length limits; shorten the destination path or switch to robocopy.
- Check free space on the destination before a full /e copy; a failed run can leave a partial tree behind.
- Use /f to display full source and destination names as files are copied, which makes debugging much easier.
Troubleshooting
Nothing copied: check the current folder and confirm the source path exists; a typo silently yields zero files. Add /f to see what xcopy is processing.
Prompt appears in a script: add /i for directory confirmation and /y for overwrites. Re-test interactively before scheduling.
Access denied: rerun Command Prompt as administrator, or confirm your account can read the source. Protected system folders require elevation.
Files failed to copy: they may be locked or read-only. Add /r where appropriate, close the programs using the files, or copy during a quiet period.
Hidden files missing: add /h. Empty folders missing: add /e.
Permissions lost: add /o and run elevated. If that fails, the destination may not support ACLs.
If that did not work: delete the partial destination folder (this removes only the copy, not the source), then rerun the tested command with logging. If it still fails, use robocopy with the same paths to see whether the issue is the source, the destination or the copy tool.
Frequently Asked Questions
Is xcopy still available in Windows?
Yes, it is included with current Windows versions. Microsoft recommends robocopy for demanding jobs, but xcopy still works and remains common in older scripts.
What is the difference between /s and /e?
/s copies subfolders but skips empty ones. /e copies all subfolders including empty ones, and implies /s.
Does xcopy overwrite files by default?
It asks before overwriting an existing file. /y suppresses that prompt; /-y forces it.
Why did xcopy skip hidden files?
Hidden and system files are excluded unless you add /h. Read-only files need /r to be overwritten.
Can xcopy copy files that are open in another program?
Not reliably. Locked files are often skipped and appear as failures in the summary. Close the programs using them first.
Should I use xcopy or robocopy?
Use xcopy for simple folder copies and legacy scripts. Use robocopy for large jobs, network transfers, mirroring, long paths and retry logic.