Copying many files under Windows, continue on errors

If you ever tried to copy or move many files using Windows Explorer, you’ll know the problem: you start the process, come back hours later and expect it to be finished and it did almost nothing.

It may have hit a file that is a system file and waited for you to click ‘Yes’ for the last hours, not copying anything else. Or it may have tried to move a file that is currently in use or whatever and simply aborts the whole process, not even trying to copy the others.

(If you don’t know the problem you most likely never made a simple backup on a single desktop computer, like lots of people on the MS mailing lists who don’t even get the problem.)

The solution is to use a command line utility to copy the files. Windows comes with the xcopy command which does the job. From the shell prompt (Start => Run command…) you could try something like this:

xcopy "C:\Documents and Settings\myuser\*.*" "D:\Backup\*.*" /C /H /R /Y /S /E

or read the official documentation for details and more options. The command line switches above mean:

/C – Continue even on error
/H – Copy hidden and system files, too
/R – Overwrite read-only files
/Y – Copy without confirming replacement of existing files
/S – Copies directories and subdirectories unless they are empty
/E – Copies any subdirectories, even if they are empty

I prefer to use rsync though. The best way to get it under Windows is to install Cygwin and choose it during the package selection phase of the installation or update procedure.

You can then start the BASH that comes with Cygwin (which is way better than cmd.exe) and use rsync from there:

rsync -avh "/cygdrive/c/Documents and Settings/myuser" "/cygdrive/d/Backup/"

The options above mean:

-a archive mode
-v increase verbosity
-h output numbers in a human-readable format

IMPORTANT: Note that with rsync, it makes a difference whether there is a slash (“/”) at the end of the source directory or not (…/myuser/ vs. …/myuser in the example above)! A trailing “/” on a source name means “copy the contents of this directory”. Without a trailing slash, it means “copy the directory”. (So usually you do NOT want the slash.)

Type man rsync in the bash shell for more details.


About dfspspirit

PhD student in bioinformatics, interested in photography, level design, digital image manipulation, architecture and, of course, bioinformatics.
This entry was posted in windows and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s