title: ". was unexpected at this time" generated from batch script line 'if exist [file] (...
body: <p>relevant code looks like this:</p>
  
  <pre><code>cd /d %~dp0
  
  if exist filename.txt (
      echo %date% %time% *** text... &gt;&gt; filename2.txt
      echo ==============================
      echo ===  text.......           ===
      echo ===  text.......           ===
      echo ===  text....... (text...) ===
      echo ===  text (text... 
      echo ===  text...).
      :loop
          set /p "varx= text: "
      if "%varx%" neq "xxxx" goto loop
  
   ... more script...
  
  )
  </code></pre>
  
  <p>Have searched high and low for solutions...</p>
  
  <ul>
  <li><p>was pointed in direction of If statement groupings here:
  <a href="https://www.petri.com/forums/forum/windows-scripting/general-scripting/57625-if-exists-file-was-unexpected-at-this-time" rel="nofollow noreferrer">https://www.petri.com/forums/forum/windows-scripting/general-scripting/57625-if-exists-file-was-unexpected-at-this-time</a>  - NO GO </p></li>
  <li><p>was pointed in direction of problems with loops in If blocks, here:
  <a href="https://stackoverflow.com/questions/8481558/windows-batch-goto-within-if-block-behaves-very-strangely">(Windows batch) Goto within if block behaves very strangely</a>  - NO GO</p></li>
  <li><p>Was pointed in direction of using @setlocal enabledelayedexpansion or @setlocal enableextensions (can't track down where) - NO GO</p></li>
  <li><p>tried passing filename via set /p varfile="filename" and if exist %varfile% - NO GO</p></li>
  <li><p>of course thought there were other parts of code causing error -- NO GO</p></li>
  </ul>
  
  <p>The thing is that this WAS working for a long while...then I changed what I thought was some innocuous stuff and cannot figure out where the problem lies...</p>
  
  <p>such an obscure problem to solve..ugh!</p>