tomasz86 Posted June 8, 2011 Share Posted June 8, 2011 (edited) 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 June 8, 2011 by tomasz86 Link to comment Share on other sites More sharing options...
allen2 Posted June 8, 2011 Share Posted June 8, 2011 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. Link to comment Share on other sites More sharing options...
tomasz86 Posted June 10, 2011 Author Share Posted June 10, 2011 (edited) 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 June 10, 2011 by tomasz86 Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 29, 2011 Share Posted June 29, 2011 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... Link to comment Share on other sites More sharing options...
tomasz86 Posted June 29, 2011 Author Share Posted June 29, 2011 Would such program not work under Win2k? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 30, 2011 Share Posted June 30, 2011 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) Link to comment Share on other sites More sharing options...
tomasz86 Posted June 30, 2011 Author Share Posted June 30, 2011 I have .NET Framework 1.1, 2.0 and 3.5 installed... but I don't have the skills to write such a program Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 30, 2011 Share Posted June 30, 2011 I don't have the skills to write such a program 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. Link to comment Share on other sites More sharing options...
dencorso Posted June 30, 2011 Share Posted June 30, 2011 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. Link to comment Share on other sites More sharing options...
jaclaz Posted June 30, 2011 Share Posted June 30, 2011 (edited) I would use fvertest and avoid .Net Here:http://www.westmesatech.com/wast.html@dencorsoI 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? jaclaz Edited November 15, 2011 by jaclaz Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 30, 2011 Share Posted June 30, 2011 I would use fvertestThat's just yet another tool that reports the version, hardly an automatic "xcopy replacement with built-in version comparison". Link to comment Share on other sites More sharing options...
tomasz86 Posted June 30, 2011 Author Share Posted June 30, 2011 (edited) This is the script where xcopy is used (this part is taken from HFSLIP). It's explained in details in this topic.@ECHO OFFCOLOR 1FIF 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):HFEXTRACTECHO Unpacking %HF%MD TEMP\HF&START/WAIT HF\%HF% /Q /X:TEMP\HFECHO.XCOPY/DEHRY TEMP\HF HFMERIF EXIST TEMP\HF\UPDATE\update.inf COPY TEMP\HF\UPDATE\update.inf TEMP\%HF%.infIF EXIST TEMP\HF\UPDATE\update_w2k.inf COPY TEMP\HF\UPDATE\update_w2k.inf TEMP\%HF%.infIF EXIST TEMP\HF\UPDATE\update_win2k.inf COPY TEMP\HF\UPDATE\update_win2k.inf TEMP\%HF%.infCOPY TEMP\HF\UPDATE\update.ver TEMP\%HF%.verRD/Q/S TEMP\HFECHO.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\HF2. files from TEMP/HF are copied to HFMER using xcopy3. TEMP/HF is deleted4. another update unpacked to TEMP/HF5. 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 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 June 30, 2011 by tomasz86 Link to comment Share on other sites More sharing options...
jaclaz Posted June 30, 2011 Share Posted June 30, 2011 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 versionSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONSET SOURCE=%~dpnx1IF "%2"=="" GOTO :ERROR2SET TARGET=%~dpnx2SET TARGETDIR=%~dp2IF "%TARGET:~-1,1%"=="\" SET TARGET=%~dp2%~nx1IF "%~x1"=="" GOTO :ERROR1IF NOT EXIST %SOURCE% GOTO :ERROR1IF NOT EXIST %TARGETDIR%\NUL CALL :ERROR2FOR /F "tokens=1 delims=[]" %%A IN ('fvertest.exe %source%') DO (SET V_source=%%AECHO %source% version is %%AFOR /F "tokens=1 delims=[]" %%B IN ('fvertest.exe %target%') DO (SET V_target=%%AECHO %target% version is %%Bfvertest.exe -v %%B %target%REM Insert here checks based on Errorlevel and "UNecho/modify" the followingECHO Errolevel is !ERRORLEVEL!ECHO COPY /B %SOURCE% %TARGET%))SET V_GOTO :EOF:ERROR1ECHO.ECHO SOURCE %source% is missingGOTO :EOF:ERROR2ECHO.ECHO TARGET %target% is missingGOTO :EOFPlease note how the above is V_copy.cmd and NOT V_xcopy.cmd. jaclaz Link to comment Share on other sites More sharing options...
dencorso Posted June 30, 2011 Share Posted June 30, 2011 @dencorsoI 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? No. Not by any means! That would be too easy... 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... 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. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 1, 2011 Share Posted July 1, 2011 It takes only a few lines of batch to implement the file version checkYou'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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now