1

I need to get version of a file but then I need to use just a part of it in order to perform some further actions (e.g. compare it and continue according to the result).

Example: File version is 17.5.834.0, what I need to get and use is just the 834 number.

I use the following to get the number and work with it:

@echo off
if exist "c:\Program Files\myprg\myfile.exe" SET prgfolder=c:\Program Files\myprg
for /f "usebackq delims=" %%a in (`"WMIC DATAFILE WHERE name='%prgfolder:\=\\%\\myfile.exe' get Version /format:Textvaluelist"`) do (
    for /f "delims=" %%# in ("%%a") do set "%%#"
)
echo %version%
if %version% gtr 17.5.3000.0 echo Hello World

The echo prints the whole number and when it is e.g. 17.5.834.0 then it does not work with the if gtr 17.5.3000.0. My idea was to extract just the third number and adjust the IF then. Thank you in advance for any tip.

Petr Kolis
  • 33
  • 4

1 Answers1

0

You can use vbscript to get file version .

Try my way :

@echo off
Rem Your file : 
Set "File=C:\Program Files\Windows Mail\wabmig.exe"

cd /d "%~dp0"
Echo Set objFSO = CreateObject("Scripting.FileSystemObject")>>Q.vbs
Echo Wscript.Echo objFSO.GetFileVersion("%File%")>>Q.vbs
FOR /F %%A IN ('cscript //nologo Q.vbs') DO Set version=%%A
Del "Q.vbs"
echo %version%
if %version% gtr 17.5.3000.0 echo Hello World