Page 1 of 1

Compare a list of strings to find the biggest nummber

Posted: 16 Jul 2010 01:42
by firebloodphoenix
Hello im a noob here
i have a batch to preform updates on a other program
basically i have a list of variables that is actual numbers
i need to find the biggest number to tel my program to update from that file rather then a other one
my current code:

Code: Select all

if "%cver%" GTR "%dver%" set comp1=0

can only find the greatest between 2 verbals but i have 20 for it too look in

Re: Compare a list of strings to find the biggest nummber

Posted: 16 Jul 2010 05:45
by aGerman
If you have a list in a file, you could use the SORT command.
If you have a set of variables, you should tell us which nomenclature the variable names do have (var1, var2, ... or varA, varB, ...), to find an algorithm to run over all this names.

Regards
aGerman

Re: Compare a list of strings to find the biggest nummber

Posted: 16 Jul 2010 06:45
by firebloodphoenix
ok here is the relevant part of the code:

Code: Select all

@Echo off

:start
set drive=c
:repeat
set CHECK=no
set %drive%ver=0
set %drive%date=none
dir %drive%:\ 2>&1|findstr /b /i /r /c:" Volume in drive ">nul
IF "%errorlevel%"=="1" (goto driverror)
if exist %drive%:\nodv4_upd\update.ver (set CHECK=Yes)
IF %CHECK%==Yes (goto found) else (goto notfound)
:found
Echo ----------------------------
Echo ----------------------------
echo Found updates on %drive%:
if exist %drive%:\nodv4_upd\em002_32_l2.nup (set ENGINE2=Yes)
IF %CHECK%==Yes (goto e2found) else (goto e2notfound)
:e2found
Echo Found ENGINE2
set ver=0
set date=none
Echo Now looking at file version
for /f "skip=2 tokens=2 delims== " %%a in ('find "version=" %drive%:\nodv4_upd\em002_32_l2.nup') do set ver=%%a
for /f "skip=2 tokens=3 delims== " %%a in ('find "version=" %drive%:\nodv4_upd\em002_32_l2.nup') do set date=%%a
Echo %ver% %date%
set %drive%ver=%ver%
Echo ----------------------------
Echo ----------------------------
goto end
:driverror
echo Could not read Drive %Drive%:
goto end
:e2notfound
echo Culd not find ENGINE2
echo can not use updates
:notfound
echo updates not found on %drive%
goto %drive%
:end
goto %drive%
:c
set drive=d
goto repeat
:d
set drive=e
goto repeat
:e
set drive=f
goto repeat
:f
set drive=g
goto repeat
:g
set drive=h
goto repeat
:h
set drive=i
goto repeat
:i
set drive=j
goto repeat
:j
set drive=k
goto repeat
:k
set drive=l
goto repeat
:l
set drive=m
goto repeat
:m
set drive=n
goto repeat
:n
set drive=o
goto repeat
:o
set drive=p
goto repeat
:p
set drive=q
goto repeat
:q
set drive=r
goto repeat
:r
set drive=s
goto repeat
:s
set drive=t
goto repeat
:t
set drive=u
goto repeat
:u
set drive=v
goto repeat
:v
set drive=w
goto repeat
:w
set drive=x
goto repeat
:x
set drive=y
goto repeat
:y
set drive=z
goto repeat
:z
Echo Done checking for Updates
Echo Now Looking for the latest updates
pause


Contents of :
em002_32_l2.nup
this file is the main file that contains the update info
And this file is the file that usely changes
the "version=5276" changes with etch new update to eg "version=5277"
so i would rather find the latest version then a older one
the variable is set to %drive%ver for etch drive eg. %cver%,%dver%,%ever% ect

Code: Select all

[update_info]
name=ENGINE2
version=5276 (20100713)
versionid=5276
build=7465
type=engine
category=engine
level=2
base=7363
date=13.07.2010
platform=x86
group=perseus,ra
filesize=695304
crc=5681181
buildregname="EngineBuild"
filename="em002_32.dat"


Also needs A file called:
update.ver
In a folder of a root called:
nodv4_upd

Re: Compare a list of strings to find the biggest nummber

Posted: 16 Jul 2010 07:59
by aGerman
Hmm, tricky but doable.
First you should change this line

Code: Select all

set %drive%ver=%ver%

to

Code: Select all

set ver_%drive%=%ver%

because it's easier to process variable names with the same beginning.

Now try this below the label :z

Code: Select all

for /f "delims=" %%a in (
  '^(@echo off^&for /f "delims== tokens=2" %%b in ^('set ver_'^) do echo %%b^)^|sort'
) do set "x=%%a"
echo Latest version: %x%.


Regards
aGerman

Re: Compare a list of strings to find the biggest nummber

Posted: 17 Jul 2010 02:36
by firebloodphoenix
I like your kung-foo,thanks a lot it works like a bomb!
i had to add a few more "if" lines at the bottom to get the drive specified for update but thanks again!!!