Page 1 of 1

Trouble with ROBOCOPY - copy files to destination that don't already exist

Posted: 10 Aug 2023 09:14
by SIMMS7400
HI All -

I have a few folders & contents (including subdirecotries) I need to copy from source to target. I need to do this frequently but what's happening is that it's copying everything each time I run the ROBOCOPY. I've tried to modiy it but having no luck.

Here's what I have:

Code: Select all

ROBOCOPY "source" "dest" /s /e /xo /log+:"output.txt"
I also read ROBOCOPY will ignore any files in destination that already exists that match identically and I do have that, but still copies those.

I need to copy files that exist in the SOURCE but not int he destination. And only IF the source file is newer than the destination, then copy.
Any help is greatly appreciated. Thank you!

Re: Trouble with ROBOCOPY - copy files to destination that don't already exist

Posted: 10 Aug 2023 16:30
by mataha
Take a look at /im; /mir might be relevant for your use-case as well.

Re: Trouble with ROBOCOPY - copy files to destination that don't already exist

Posted: 11 Aug 2023 01:53
by GeoffVass
If the source and destination have different file systems, eg NTFS and FAT or NTFS and some NAS running Linux/Samba, the date-stamp granularity is different and so Robocopy will always copy the file again. The remedy is to use /FFT which takes into account the tiny date-stamp differences.

Also be careful with /MIR because this will 'mirror' the source and the destination; it will remove a file from the destination if it was removed from the source, and will overwrite newer files in the destination if the files in the source are older. Although I note you use /xo - your usage seems to be to only copy new or updated files.

Additionally you might want to use /xj so the copy operation doesn't follow any junction points.

Re: Trouble with ROBOCOPY - copy files to destination that don't already exist

Posted: 08 Jun 2024 06:01
by LeoHarrison
The issue with your Robocopy command is that it's set to copy everything by default (/s for subdirectories, /e for empty folders). To achieve your goal of copying only newer files, you can use the /UB flag.

Here's the modified Robocopy command:

Code: Select all

ROBOCOPY "source" "dest" /s /e /xo /UB /log+:"output.txt"
- Make sure the destination folder exists before running Robocopy.
- You can test the command with the /njh flag which simulates the copy operation without actually copying the files. This helps identify any potential issues before running the actual copy.
- Also you can use GUI alternatives to Robocopy like Gs Richcopy 360 or Syncback which will make it easy and save the time.