title: What is the proper way to test if a parameter is empty in a batch file?
body: <p>I need to test if a variable is set or not.  I've tried several techniques but they seem to fail whenever <code>%1</code> is surrounded by quotes such as the case when <code>%1</code> is <code>&quot;c:\some path with spaces&quot;</code>.</p>
  <pre><code>IF NOT %1 GOTO MyLabel // This is invalid syntax
  IF &quot;%1&quot; == &quot;&quot; GOTO MyLabel // Works unless %1 has double quotes which fatally kills bat execution
  IF %1 == GOTO MyLabel // Gives an unexpected GOTO error.
  </code></pre>
  <p>According to <a href="http://www.computerhope.com/if.htm" rel="noreferrer">this site</a>, these are the supported <code>IF</code> syntax types. So, I don't see a way to do it.</p>
  <pre><code>IF [NOT] ERRORLEVEL number command
  IF [NOT] string1==string2 command
  IF [NOT] EXIST filename command
  </code></pre>
  <p>UPDATE: on 2020-10-25, I updated the accepted answer from using brackets to using a tilde.  Everyone says the tilde is better as it's more secure.  I'm a little torn cause the tilde looks more complicated and is less clear as to what it's purpose is but nevertheless, I changed it.</p>