Here is a slightly simpler version than the Joey code.
@echo off setlocal enableDelayedExpansion set max=0 for /f "tokens=1* delims=-.0" %%A in ('dir /b /ad version-*.jar') do if %%B gtr !max! set max=%%B echo higest version: version-%max%.jar
This code will work even if the version numbers have a zero prefix, if the version number is never 0 (zero). Specifying tokens = 1 * with 0 included as a separator will remove leading zeros from the version number while storing all zeros after the first non-zero digit.
There is a simpler solution if all versions have a zero prefix with a constant width. But this solution works both with a zero prefix and without it.
Joey code will fail if leading zeros are present, because this indicates octal notation. Invalid octal digits with leading zeros will be treated as strings, as a result of which the comparison will give an incorrect result. This is probably not a problem, since the original question implies that there are no leading zeros. But it's better to be safe than sorry.
dbenham
source share