tomasz86

Copy only files that have newer version?

31 posts in this topic

Thanks, dencorso :) I'll try it out as soon as possible.

I've prepared an updated/fixed version of the script I posted above:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET SOURCEDIR=
SET DESTINATIONDIR=
IF EXIST "%DESTINATIONDIR%" (
FOR /F %%I IN ('DIR/A-D/B "%SOURCEDIR%"') DO (
IF EXIST "%DESTINATIONDIR%\%%I" (
FOR /F "tokens=5" %%J IN ('FILEVER "%SOURCEDIR%\%%I"') DO IF NOT "%%J"=="-" (
FOR /F "tokens=5" %%J IN ('FILEVER "%SOURCEDIR%\%%I"') DO SET SOURCEVER=%%J
FOR /F "tokens=5" %%J IN ('FILEVER "%DESTINATIONDIR%\%%I"') DO SET DESTINATIONVER=%%J
FOR /F "tokens=1-4 delims=." %%I IN ("!SOURCEVER!") DO (
SET SOURCEVER1=%%I
SET SOURCEVER2=%%J
SET SOURCEVER3=%%K
SET SOURCEVER4=%%L
)
FOR /F "tokens=1-4 delims=." %%I IN ("!DESTINATIONVER!") DO (
SET DESTINATIONVER1=%%I
SET DESTINATIONVER2=%%J
SET DESTINATIONVER3=%%K
SET DESTINATIONVER4=%%L
)
IF !SOURCEVER! EQU !DESTINATIONVER! (
XCOPY/DY "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
FOR /F %%J IN ('XCOPY/DY "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" ^| FIND "0"') DO IF !ERRORLEVEL! NEQ 0 ECHO %SOURCEDIR%\%%I
DEL/Q "%SOURCEDIR%\%%I"
)
IF EXIST "%SOURCEDIR%\%%I" IF !SOURCEVER1! GTR !DESTINATIONVER1! (
MOVE/Y "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
ECHO %SOURCEDIR%\%%I
)
IF EXIST "%SOURCEDIR%\%%I" IF NOT !DESTINATIONVER1! GTR !SOURCEVER1! IF !SOURCEVER2! GTR !DESTINATIONVER2! (
MOVE/Y "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
ECHO %SOURCEDIR%\%%I
)
IF EXIST "%SOURCEDIR%\%%I" IF NOT !DESTINATIONVER1! GTR !SOURCEVER1! IF NOT !DESTINATIONVER2! GTR !SOURCEVER2! IF !SOURCEVER3! GTR !DESTINATIONVER3! (
MOVE/Y "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
ECHO %SOURCEDIR%\%%I
)
IF EXIST "%SOURCEDIR%\%%I" IF NOT !DESTINATIONVER1! GTR !SOURCEVER1! IF NOT !DESTINATIONVER2! GTR !SOURCEVER2! IF NOT !DESTINATIONVER3! GTR !SOURCEVER3! IF !SOURCEVER4! GTR !DESTINATIONVER4! (
MOVE/Y "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
ECHO %SOURCEDIR%\%%I
)
) ELSE (
XCOPY/DY "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
FOR /F %%J IN ('XCOPY/DY "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" ^| FIND "0"') DO IF !ERRORLEVEL! NEQ 0 ECHO %SOURCEDIR%\%%I
)
) ELSE (
MOVE "%SOURCEDIR%\%%I" "%DESTINATIONDIR%" >NUL
IF !ERRORLEVEL! EQU 0 ECHO %SOURCEDIR%\%%I
)
)
) ELSE (
MD %DESTINATIONDIR%
COPY %SOURCEDIR%\*.* %DESTINATIONDIR% >NUL
FOR /F %%I IN ('DIR/A-D/B %SOURCEDIR%') DO ECHO %SOURCEDIR%\%%I
)
PAUSE

Be careful because this one actually moves some of the files.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.