Windows cmd shell xcopy to network directory doesn't work

Flyckten picture Flyckten · Jan 10, 2014 · Viewed 24.2k times · Source

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).

My code:

xcopy "C:\Source" "T:\Backup" /d/i/s/q

(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)

Source contains both subdirectories and files (.txt).

The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:

"An error occured when the file The directory is not empty. was being created. The folder "T:\Backup" could not be created. 0 files copied. (Translated from Swedish so not 100% original)

The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.

Anyone who can understand why this doesn't work for the network drive? Should I try Another command such as robocopy?

Answer

selbie picture selbie · Jan 10, 2014

Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.

Example:

robocopy c:\source T:\backup /E

That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.

And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):

robocopy c:\source T:\backup /E /LOG:nul