If else logic question [SOLVED]
Posted: 19 Aug 2021 09:17
I'm having some issues with the logic of an if else block. I can get it to work just fine if I rely on goto statements, but I'd rather not. I am simply checking if an exe file exists and then capturing the version if it does else setting the variable to Not Installed otherwise. The code to capture the version works just fine:
However, this does not work if I place it in an if else block:
I'm using notepad.exe as an example, but this could be any file. I'm sure I'm missing something obvious, but I haven't been able to discover what it is. Any help would be appreciated.
Code: Select all
set "nPad=%windir%\notepad.exe"
set "nPadloc=%nPad:\=\\%
for /f "tokens=2 delims==" %%e in ('wmic datafile where "name='%nPadloc%'" get version /value') do for /f "delims=" %%f in ("%%e") do set "nPadv=Version: %%e"
echo %nPadv%
Code: Select all
if exist "%windir%\notepad.exe" (
set "nPad=%windir%\notepad.exe"
set "nPadloc=%nPad:\=\\%
for /f "tokens=2 delims==" %%e in ('wmic datafile where "name='%nPadloc%'" get version /value') do for /f "delims=" %%f in ("%%e") do set "nPadv=Version: %%e"
) else (
set "nPadv=Not Installed"
)
echo %nPadv%