Robocopy to ONLY copy changed files

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Robocopy to ONLY copy changed files

Post by MigrationUser »

14 Jun 2006 15:44
NDog

In a batch file I am writing I want robocopy to ONLY copy files that are of different file size from the source to the destination. These are large 1.4GB files, and I was previously using FC to compare them, however FC needs to to load the files to check them, and this takes too long on a network.
The reason I need to do this is that the destination and the source keep changing time stamps (as they are being read frequently), but they do not change file size.
If I run robocopy %source% %destination% /XO /XN, will this only overwrite the sources file to the destination if the sources file-size changes?
If not how can I do this?
Thanks

cmd, vbs, ps, bash
autoit, python, swift

----------------------------

#2 14 Jun 2006 21:45
Simon Sheppard


By default Robocopy will consider the file changed if the file size changes OR if the timestamp changes
so all you need is
robocopy %source% %destination%

----------------------------

#3 15 Jun 2006 02:57
NDog


In theory that is supposed to happen, however in reality when i use:

robocopy %source% %destination%
it copies older files
it copies newer files
even though the source and destination are identical!!!
(I checked them with comp)

This is the specific code (using fcmp.exe as its faster than COMP or FC)

Code: Select all

set file=14GBfile.txt
fcmp D:\myfiles\%file% \\games00\d$\myfiles\%file%
::files are identical!
robocopy D:\myfiles \\games00\d$\myfiles %file%
::still copies them as newer even though they are identical!!!
In theory I CAN do this, however it STILL needs to load the files to compare them!!

Code: Select all

set file=14GBfile.txt
fcmp D:\myfiles\%file% \\games00\d$\myfiles\%file%
if errorlevel 1 robocopy D:\myfiles \\games00\d$\myfiles %file%
All I want to do is compare the file-sizes and if they are not identical - then robocopy %source% %destination%,
so the question maybe I should ask is: how can i check the filesize of the files first, then if they mismatch, robocopy
(without using fc or comp or fcmp, since they load the files, I need to be able just to check the filesize without loading the entire 14gb files to compare them)

Thanks again.

cmd, vbs, ps, bash
autoit, python, swift

----------------------------

#4 15 Jun 2006 20:44
Simon Sheppard


- something like this

Code: Select all

FOR %%G in (%file1%) do set _size1=%%~zG
FOR %%G in (%file2%) do set _size2=%%~zG

IF %_file1%==%_file2% echo The files are same size
/untested

----------------------------

#5 16 Jun 2006 06:42
NDog


Thank you very much!

cmd, vbs, ps, bash
autoit, python, swift
User avatar
Simon Sheppard
Posts: 49
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Robocopy to ONLY copy changed files

Post by Simon Sheppard »

This is an old thread, but a common reason for robocopy repeatedly copying files on every run is if the source and destination have different filesystems which return the date modified to a slightly greater or lesser accuracy.

If everything is running NTFS there should be much less of that happening.
SolaWatson
Posts: 1
Joined: 2021-Nov-03, 8:33 am

Re: Robocopy to ONLY copy changed files

Post by SolaWatson »

If will do a process like this (to copy the changed files only ) I would not use Robocopy, tons of free/paid tools can do this task like Duplicati, Gs Richcopy 360 , SyncThing,GoodSync ... etc , all have a GUI interface which make it easy
Post Reply