title: batch files: using IF EXIST
body: <p>Consider the following batch file:</p>
  
  <pre><code>=================== exist-test.bat
  @echo off
  set pavtest=
  if EXIST %programfiles(x86)%\AAA (
       set pavtest = AAA
       echo we have done the AAA test
  ) ELSE (
      if EXIST %programfiles%\BBB (
       set pavtest = BBB
       echo we have done the BBB test
      )
  )
  </code></pre>
  
  <p>Suppose neither the AAA nor BBB folders exist. Then I'd think that the logic would be:</p>
  
  <ol>
  <li>The first IF EXIST is false, so control transfers to ELSE</li>
  <li>The second IF exist is also false, so we skip this branch too.</li>
  </ol>
  
  <p>Instead, what happens on Win7 is that both echo statements are executed, and of course the value of pavtest at the end is BBB.</p>
  
  <p>Can anyone explain why my logic is wrong? Thanks!</p>