$vercmp function
$vercmp(version1,version2)
The $vercmp function compares two file or product versions and returns a value < 0, 0, or > 0 depending on the comparison result:
Relative versions | Result |
---|---|
version1 < version2 | < 0 |
version1 = version2 | 0 |
version1 > version2 | > 0 |
The result can be used in conditional expressions; see Examples below.
Each version parameter must consist of up to 4 decimal numbers separated by periods: a.b.c.d, from most to least significant. You may leave off less significant numbers; any missing numbers are treated as 0. Therefore, 2.1.0.0, 2.1.0 and 2.1 are equivalent.
Note: The comparison is done numerically, not as text. This means, for example, that $vercmp(2.19, 2.2) is > 0, because 19 > 2. It also means that 2.2 and 2.20 are not the same version (but 2.2 and 2.2.0 are).
Tip: You can use the $fverf and $fverp functions to retrieve the file and product version of a file, respectively. However, it may be more efficient and less verbose to use the $fverfcmp and $fverpcmp functions for file or product version comparisons.
Parameters
All parameters may contain symbolic references; these are resolved before the function is applied. See Examples below.
- version1
- First version for the comparison.
- version2
- Second version for the comparison.
Examples
Here are some usage examples for this function:
- <$vercmp(<$fverp(<WindowsFolder>\Notepad.exe)>, 5)>
- Returns < 0 if the Notepad.exe product version is < 5.0.0.0, 0 if it is 5.0.0.0, and > 0 if it is > 5.0.0.0. You can achieve the same effect with less typing by using <$fverpcmp(<WindowsFolder>\Notepad.exe, 5)>.
- <$vercmp(<$fverp(<WindowsFolder>\Notepad.exe)>, 5)> >= 0
- Conditional expression that evaluates to TRUE if the Notepad.exe product version is 5.0.0.0 or greater, or FALSE if not.
- <$vercmp(<$fverp(<WindowsFolder>\Notepad.exe)>, <MinVersion>)> >= 0
- Conditional expression that evaluates to TRUE if the Notepad.exe product version is greater than or equal to <MinVersion>, or FALSE if not. <MinVersion> should evaluate to something that can be parsed as a version number.