#1 14 Jun 2006 15:44

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 119
Website

Robocopy to ONLY copy changed files

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

Offline

#2 14 Jun 2006 21:45

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,019
Website

Re: Robocopy to ONLY copy changed files

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%

Offline

#3 15 Jun 2006 02:57

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 119
Website

Re: Robocopy to ONLY copy changed files

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)

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!!

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

Offline

#4 15 Jun 2006 20:44

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,019
Website

Re: Robocopy to ONLY copy changed files

- something like this

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

Offline

#5 16 Jun 2006 06:42

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 119
Website

Re: Robocopy to ONLY copy changed files

Thank you very much!


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

Offline

Board footer

Powered by FluxBB