I am trying to figure out what version of my software is installed on user's computer. The versions are 5.0, 4.0, 3.0. Version 5.0 is the latest.
- I would like to check if the user has any of these versions installed in this order.
- I have wrote a script as follows: I also added
setlocal enabledelayexpansionat the top. - I have learnt here (on stackoverlow) that I need to use
!variable!to change the value of variableVERSIONin the IF loop. - I tried it myself, but most of the examples were for echo'ing.
- Here I am changing the value of the version.
- Then update the path directory.
I am not able to make this work. Can you please help. Thank you so much.
Here is my script:
:: Find the version installed in the user's computer
:: valid versions are 5.0, 4.0, 3.0
setlocal enabledelayedexpansion
ECHO OFF
SET "error_code=0"
:: Latest Software version
SET VERSION=5.0
echo checking SOFTWARE Version: %VERSION%
:: build a path and check if it exists
SET "PATH=%PROGRAMFILES%\MYSOFT\%VERSION%"
call:CHECK_IF_VALID "%PATH%"
if %error_code% == 1 (
:: check v.4
SET VERSION=4.0
echo checking SOFTWARE Version: !VERSION!
SET "PATH=%PROGRAMFILES%\MYSOFT\%VERSION%"
call:CHECK_IF_VALID "%PATH%"
if %error_code% == 1 (
:: check v.3
SET VERSION=3.0
echo checking SOFTWARE Version: !VERSION!
SET "PATH=%PROGRAMFILES%\MYSOFT\%VERSION%"
call:CHECK_IF_VALID "%PATH%"
if %error_code% == 1 (
echo.&pause&goto:eof
)
)
)
:: Function to check if path exists
:CHECK_IF_VALID
if not exist %1 (
echo version not found...
set "error_code=1"
) else echo. Version found...
echo.
goto:eof
EXIT
\MYSOFT\5.0,\MYSOFT\4.0andMYSOFT\3.0supposed to be file names or directory names?\mysoft\5.0,mysoft\4.0etc are the folder names.