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: 544
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: 35
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.

LeoHarrison
Posts: 7
Joined: 20 Feb 2020 04:32

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

#4 Post by LeoHarrison » 08 Jun 2024 06:01

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.

Post Reply