Windows cmd shell xcopy to network directory doesn't work

28,847

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
Share:
28,847

Related videos on Youtube

Flyckten
Author by

Flyckten

Updated on July 18, 2022

Comments

  • Flyckten
    Flyckten almost 2 years

    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?

  • Flyckten
    Flyckten over 10 years
    So robocopy doesn't copy files that already exists at target by default? Seems to work, thanks a lot!
  • Artjom B.
    Artjom B. over 8 years
    I have no idea what you're trying to say here. Are you recommending that OP should try robocopy? If so, can you give an example?
  • spider
    spider about 8 years
    XCOPY "DRIVE LETTER:\source of file" "\\computer name\DRIVE LETTER\destination of file\" /D /E /C /R /I /K /Y /f
  • spider
    spider about 8 years
    robocopy takes longer and it works fine for file name longer thin 256