BAT if% environment variable folder% exists (system folders)

I would like to check if% PROGRAMFILES (X86)% \ Folder exists, but it looks like if EXIST doesn't like environment variables: /

my way:

if EXIST %PROGRAMFILES(X86)%\Folder (
    set VAR=%PROGRAMFILES(X86)%\Folder
)

      

no matter how I try, it always outputs false ...

+3


source to share


2 answers


if EXIST "%PROGRAMFILES(X86)%\Folder" (
    set "VAR=%PROGRAMFILES(X86)%\Folder"
)

      



+5


source


To check if an environment variable exists:

if defined VARIABLE echo Yep, it defined.

      

The following also works and prints the current value of the variable if set.



set VARIABLE && echo Found it! || echo Nope, sorry!

      

Note that SET also responds to prefixes, so if you have a var named VARIABLE then "set var" and "set v" will also return true.

Not the question you asked, but this is how I read the title, so someone else might have the same question.

+1


source







All Articles