Exouxas wrote:Nevermind about the splitting 2.8 into two parts, figured i could do: if 2.8 gtr 2.9 lol
Actually that won't be reliable because "DOS" only understands integral numbers. It will do an alpha comparison instead of a numeric comparison because of the period. This will result in 2.8 being greater than 10.1 - not what you want
You can either split the version into two parts like you originally planned, or you can make sure you 0 pad the parts to account for as many versions as you think are likely. For example, 02.08 will allow up to 99 versions and subversions. Zero padding will allow adding a third or fourth subversion as needed without requiring changes to code. For example, "02.08.02" is greater than "02.08". Another advantage of zero padding is you could add alpha suffixes to the parts if you wanted and the comparisons will still work.
For the remainder of this post I'll assume you are not zero padding.
Bob D wrote:use FIND to find the line(s) in question, push the output to a file, read the file into a variable, search the variable for the target.
...
...The (code) may fall over if there is more than one line in the original file that contains the target string.
No need for a temporary file or multiple commands. Steps 1 through 6 can be accomplished with one relatively simple FOR /F construct using FINDSTR or FIND. I tend to favor FINDSTR when either will work, though I don't have a compelling reason for this.
Code: Select all
set "verp1="
set "verp2="
for /f "tokens=2,3 delims=#." %%a in ('findstr /i /c:"version#" file') do set /a "verp1=%%a, verp2=%%b"
If version# appears in multiple lines, than the last one detected will "win"
If you want to keep the 1st line that contains version# instead, then you simply use a GOTO in the loop:
Code: Select all
set "verp1="
set "verp2="
for /f "tokens=2,3 delims=#." %%a in ('findstr /i /c:"version#" file') do (
set /a "verp1=%%a, verp2=%%b"
goto :endLoop
)
:endLoop
I clear verp1 and verp2 before the FOR /F just in case the version# line is not found.
The above code will fail if the version does not have the correct format (it must be purely numeric with one period between the parts)
It will also fail if # or . appears in the line prior to version#
There are ways to safeguard against this using regular expressions and FINDSTR.
With slightly more complex code it is also possible to support a line like
Code: Select all
rem author#Joe Smith# version#2.8#
It all depends on how far you want to take the concept.
Dave Benham