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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 541
Joined: 07 Jan 2016 07:47

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

#1 Post by SIMMS7400 » 10 Aug 2023 09:14

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!

mataha
Posts: 32
Joined: 27 Apr 2023 12:34

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

#2 Post by mataha » 10 Aug 2023 16:30

Take a look at /im; /mir might be relevant for your use-case as well.

GeoffVass
Posts: 10
Joined: 04 Oct 2021 17:34

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

#3 Post by GeoffVass » 11 Aug 2023 01:53

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.

Post Reply