tomasz86

Copy only files that have newer version?

31 posts in this topic

By using xcopy with /d swich it's possible to copy only files that are newer.

I wonder if it is possible to copy only files whose version is newer even though their date of creation may be older.

Is there any program than can do it from a command line?

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

No most tools out there doesn't check the version. You'll need to script it using filever.exe (from xp sp2 support tools) or do a vbs a explained there.

0

Share this post


Link to post
Share on other sites

Thank you :)

I guess filever.exe from Win2k support tools is also OK ;) Actually I compared w2k filever.exe and w2k3 filever.exe and the only difference is that there is no "/R" switch in the older one.

I found a better tool :)

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

It would be pretty easy to make a xcopy-like program that checks version using C# (only copies files with newer versions, or makes a list of them or whatever). Not sure if that's any help as you're seemingly using win2k...

0

Share this post


Link to post
Share on other sites

Would such program not work under Win2k?

0

Share this post


Link to post
Share on other sites

Would such program not work under Win2k?

It depends on which version of the .NET framework one uses. The newer versions have some really nice and useful additions like LINQ, but those frameworks don't run on Win2k. It's still fairly simple to write using an older version of the .NET framework (v2). It's just more work to do so.

There are a few things one would have to think of ahead though, like what to do when one or both files don't have an embedded "version" (just blindly overwrite? overwrite if timestamp is newer? just warn and copy nothing? ...) You can do just about anything. You could log to any file format (like lists of newer/older/unchanged/overwritten files and such), you could export a csv file with the differences and so on (you could include file hashes too). In fact, it's more work thinking about it (requirements, things that might occur and how to handle them, etc) than actually writing it.

Seriously, it's not that much work. Getting the list of all files (including all subfolders) using Directory.GetFiles method takes a single line of code, getting a file version using FileVersionInfo.GetVersionInfo is another simple one-liner. Then you just have to iterate through the list of files using a plain "foreach" statement and comparing the versions (copying files as necessary, using the File.Copy method -- another trivial one-liner)

0

Share this post


Link to post
Share on other sites

I have .NET Framework 1.1, 2.0 and 3.5 installed... but I don't have the skills to write such a program :o

0

Share this post


Link to post
Share on other sites

I don't have the skills to write such a program :o

I can take care of that ;)

You'd just have to confirm the desired behavior. Like:

-if the file in "source" doesn't exist in "destination" then just copy it anyway?

-if the file in "source" doesn't have a "version" embedded in it (like say, a picture), then we copy it to "destination" only if the timestamp is newer?

-any other particular "rules" you'd want it to obey?

It's just those little things we have to figure out beforehand (requirements). Then it would only take a few minutes to write such a program.

0

Share this post


Link to post
Share on other sites

One caveat: both versions the hexadecimal and the text string File Version should be checked because they are not always the same...

MS filever.exe v. 5.2.3754.0 returns the hex file version. But in the properties tab one has the hex displayed above, and the text one below, when one selects File Version. Among the Win XP files ole32.dll is a simple example of this fact, but ole2.dll is even better.

The text File Version is part of VS_FIXEDFILEINFO, which is a member of VS_VERSION_INFO. Now, the hexadecimal File Info is itself another a member of VS_VERSION_INFO but it resides inside a VarFileInfo structure, IIRR.

0

Share this post


Link to post
Share on other sites

I would use fvertest and avoid .Net :ph34r:

Here:

http://www.westmesatech.com/wast.html

@dencorso

I am failing to see the practical implications.

Do you mean that there are executables around with SAME "hex" version BUT different "text" version and that the latter may be newer than the first AND that it is a reliable way to get the newer file? :unsure:

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

I would use fvertest

That's just yet another tool that reports the version, hardly an automatic "xcopy replacement with built-in version comparison".

0

Share this post


Link to post
Share on other sites

This is the script where xcopy is used (this part is taken from HFSLIP). It's explained in details in this topic.

@ECHO OFF

COLOR 1F

IF EXIST HF\*.EXE (

IF EXIST HFMER RD/Q/S HFMER

IF EXIST TEMP RD/Q/S TEMP

MD HFMER TEMP

DIR/B/A-D/OGN/ON HF\*.EXE>HFMER.TXT

DIR/B/A-D/OGN/ON HF\*.EXE>TEMP\HF.TXT

SET HF=

FOR /F %%I IN (TEMP\HF.TXT) DO (SET HF=%%I&IF DEFINED HF CALL :HFEXTRACT)

DIR/B/A-D/OGN/ON HF\*.EXE>HFMER\UPDATE\eula.txt

DEL/Q/S TEMP\HF.TXT

)

IF NOT EXIST HF\*.EXE (

ECHO HF folder is empty.

ECHO.

PAUSE

EXIT

)

:HFEXTRACT

ECHO Unpacking %HF%

MD TEMP\HF&START/WAIT HF\%HF% /Q /X:TEMP\HF

ECHO.

XCOPY/DEHRY TEMP\HF HFMER

IF EXIST TEMP\HF\UPDATE\update.inf COPY TEMP\HF\UPDATE\update.inf TEMP\%HF%.inf

IF EXIST TEMP\HF\UPDATE\update_w2k.inf COPY TEMP\HF\UPDATE\update_w2k.inf TEMP\%HF%.inf

IF EXIST TEMP\HF\UPDATE\update_win2k.inf COPY TEMP\HF\UPDATE\update_win2k.inf TEMP\%HF%.inf

COPY TEMP\HF\UPDATE\update.ver TEMP\%HF%.ver

RD/Q/S TEMP\HF

ECHO.

IF NOT EXIST TEMP\HF.TXT (

FOR /F %%A IN ('dir /b TEMP\*.ver') DO (

FOR /F "skip=1 tokens=*" %%B IN (TEMP\%%A) DO (

ECHO Merging update.ver...

ECHO TEMP\%%A -- %%B

ECHO %%B >>TEMP\update.txt

)

)

ECHO [sourceFileInfo] >TEMP\update.ver

SORT TEMP\update.txt >>HFMER\UPDATE\update.ver

DEL/Q/S HFMER\UPDATE\update*.inf HFMER\createcab.cmd HFMER\UPDATE\kb*_net.cat HFMER\UPDATE\kb*_wxp.cat

COPY TEMP\*.inf HFMER\UPDATE

RD/Q/S TEMP

)

The process is like this:

1. update is unpacked to a folder TEMP\HF

2. files from TEMP/HF are copied to HFMER using xcopy

3. TEMP/HF is deleted

4. another update unpacked to TEMP/HF

5. files copied to HFMER (xcopy)

...

repeated for all updates.

If files from the second update are older than those which are already present in HFMER, they are not copied. The problem is that some files have newer version but their date is older. Actually, in case of win2k there are just a few such updates but still...

To answer your questions:

1. Yes, I would like to have it fully automated.

2. I don't know :o but I don't think there will be any pictures, just system files (dll, exe, inf, etc.).

3. No "special" rules come to my mind ;)

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

That's just yet another tool that reports the version, hardly an automatic "xcopy replacement with built-in version comparison".

Sure :).

It takes only a few lines of batch to implement the file version check, and as well only a few lines of code in C or in C# "standalone", if using .Net, it will take a few lines + a considerable amount of ".Net", with all the consequent .Net install and versioning problems on 2K.

At it's basics:

@ECHO OFF
:: V_copy.cmd - small batch sketch
:: to copy executables and dll's depending on their version
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
SET SOURCE=%~dpnx1
IF "%2"=="" GOTO :ERROR2
SET TARGET=%~dpnx2
SET TARGETDIR=%~dp2

IF "%TARGET:~-1,1%"=="\" SET TARGET=%~dp2%~nx1
IF "%~x1"=="" GOTO :ERROR1
IF NOT EXIST %SOURCE% GOTO :ERROR1
IF NOT EXIST %TARGETDIR%\NUL CALL :ERROR2


FOR /F "tokens=1 delims=[]" %%A IN ('fvertest.exe %source%') DO (
SET V_source=%%A
ECHO %source% version is %%A
FOR /F "tokens=1 delims=[]" %%B IN ('fvertest.exe %target%') DO (
SET V_target=%%A
ECHO %target% version is %%B
fvertest.exe -v %%B %target%
REM Insert here checks based on Errorlevel and "UNecho/modify" the following
ECHO Errolevel is !ERRORLEVEL!
ECHO COPY /B %SOURCE% %TARGET%
)
)
SET V_

GOTO :EOF

:ERROR1
ECHO.
ECHO SOURCE %source% is missing
GOTO :EOF

:ERROR2
ECHO.
ECHO TARGET %target% is missing
GOTO :EOF

Please note how the above is V_copy.cmd and NOT V_xcopy.cmd. ;)

jaclaz

0

Share this post


Link to post
Share on other sites
@dencorso

I am failing to see the practical implications.

Do you mean that there are executables around with SAME "hex" version BUT different "text" version and that the latter may be newer than the first AND that it is a reliable way to get the newer file? :unsure:

No. Not by any means! That would be too easy... :D

I mean that there are executables around with SAME "hex" version BUT different "text" version, *and* that also are executables around with SAME "text" version BUT different "hex" version. The different version, whichever of the two types it is, can be used to decide which is the actual newer version, but there are cases in which the actual higher version number is the older one. PE Timestamps may also be used to help sort this conundrum, in the case of Win32 executables (= PE executables). But no solution is reliable, if by that you mean works for 100% of the cases... :ph34r:

If you follow the links here, you'll see some examples. This is a noteworthy excerpt:

In a nutshell, changing oleaut32.dll from v. 2.40.4522.0 to v. 2.40.4519.0, despite all the apearances, *is an upgrade*, not a downgrade! HTH

@tomasz86: getver is reliable under Win9x/ME but unreliable under XP (where it gives the version of the file that is in memory, when you try to find the version of any file that has the same name of a loaded dll or exe file). So take care. Filever, by contrary, never lies.

0

Share this post


Link to post
Share on other sites

It takes only a few lines of batch to implement the file version check

You're just copying the one file there (where you have to manually pass in both full paths to a single file), that's still quite a long shot from being an "automated drop in replacement for xcopy with version checking" (where you pass in 2 paths and it does everything automatically). If you can do the whole thing in batch then more power to you. There's just no way I'm going to waste any time trying to write that (find all files incl subdirs, doing all the version checking including handling all the special cases like dencorso mentioned) using batch files (I avoid using batch as much as possible for my own sanity). Feel free to share a batchfile that automates the complete job, tomasz86 would surely appreciate. I just don't have that kind of time to waste.

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.