What is the proper way to test is variable is empty in a batch file, If NOT "%1" == "" GOTO SomeLabe
- by blak3r
I need to test if a variable is set or not. I've tried several techniques but they seem to fail whenever %1 is surrounded by quotes such as the case when %1 = "c:\some path with spaces".
IF NOT %1 GOTO MyLabel // This is invalid syntax
IF "%1" == "" GOTO MyLabel // Works unless %1, otherwise fatally kills bat execution
IF %1 == GOTO MyLabel // Gives an unexpected GOTO error.
According to this site. These are the support IF syntax types. So, I don't see a way to do it.
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command