[batch] file copy IF file1 != file2

April 14, 2010 at 13:18:13
Specs: Windows XP
i have a 2.8gb file, which I modify from time to time, I have a batch file that copies this file along with other smaller files to a destination. This is the only time consuming file. Can someone show me a way to copy over this file if and only if the size/time aren't the same? Hence, size/time comparison only, not content.
i tried using robocopy but still couldn't work it out. Thanks!

.


See More: [batch] file copy IF file1 != file2

Report •

#1
April 14, 2010 at 13:35:50
If it's just copy the file if newer, then you could get away with:
xcopy "bigFile" "someDest" /d /z


Report •

#2
April 14, 2010 at 15:17:35
Why /z?

Thanks, i could possibly live with "/d" might solve half my problem.

Well you see, sometimes I wanna use the "original" file, so the file date should be dated way back, and will override the destination of newer date.

So its most accurate to test both date/size before copying. If both are a match, only then it shouldn't copy.

.


Report •

#3
April 14, 2010 at 17:22:06
another possibility is to use the Archive attribute (after, that's what it was made for!)
xcopy /M
this will switch the attribute off as it copies the file. It should only get switched on again if something writes to the file (although this doesn't check for changes, just any writes).
If the archive-bit is off, that should indicate that the file is identical to the "backup" copy and thus no need to copy.

Report •

Related Solutions

#4
April 15, 2010 at 01:16:43
src=abc.txt [A] time:1pm
dst=abc.txt [A] time:2pm

xcopy /m src\abc.txt dst\abc.txt

after copying, dst abc.txt will no longer have [A], right?

sounds good so far.

.


Report •

#5
April 15, 2010 at 10:20:27
yes. you can check it using ATTRIB filename and verify there's no "A" over on left.

Report •

#6
April 16, 2010 at 03:13:20
XCOPY /D does the timing difference
There is some option somewhere to check on sizing differences, check XCOPY, XXCOPY and Robocopy

BTW, not asked, but a content check can also be done with CRC checks and such.


Report •

#7
April 16, 2010 at 03:15:50
> yes. you can check it using ATTRIB filename and verify
> there's no "A" over on left.
>

I consider that the most unreliable attribute of a file, given the fact not a lot of tools use it, and Windows behaviour should be double-checked, if you try this. I would advice to ignore this one, I've never seen a lot of smart use from this one (although it may be possible). Normally, you cannot change a file without changing the date of a file (with the only exception that FAT may only specify minutes, not seconds).


Report •

Ask Question