cmd - Can i use XCOPY to copy only files that have changed size? -


i'm trying use xcopy backup .pst files outlook , backup files have changed since last use.

normally easy using /d switch save files newer modified date outlook changes date when it's opened regardless of whether contents have changed.

is possible use if statement compare file sizes , backup if file size different (not larger or smaller)?

currently using:

xcopy /m /f /i /y c:\*.pst \\networklocation\%username%\backup 

thanks

this unbelievable tool copying cannot "update" target file. @ least xcopy cannot, , neither can robocopy afaik.
batchfile clumsy gets job done:

@echo off :: copy files targetdir if different, modified date or size or name set targetdir=backup %%f in (*.pst) call :copy_changed %%f %targetdir% goto :eof   :copy_changed    set saved=(none)    set live="%~1"    if not exist "%~2\%~1" goto :do_copy    rem compare file metadata of %1 in current dir , dir %2    pushd "%~2"    /f "tokens=3 usebackq" %%a in (`dir "%~1" ^| findstr /c:"%~1" ^|^|  echo --- `) set saved=%%a    popd    /f "tokens=3 usebackq" %%a in (`dir "%~1" ^| findstr /c:"%~1"`)  set live=%%a    if "%live%".=="%saved%". goto :eof :do_copy       echo original: %live%    echo backup:   %saved%    xcopy "%~1" "%~2" /f /y    goto :eof 

you need adjust xcopy options needs. echo lines in subroutine can deleted.
each file, batchfile collects filesize once in source folder , in destination folder , compares them literally, using dir. if equal file skipped else xcopy'd.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -