title: Batch file ErrorLevel woes
body: <p>I am writing a batch file to upgrade some systems. I need to parse a date from an xml file and save it for use later in the file. The format of the date is yyyy\MM\dd.</p>
  
  <p>What I have so far is:</p>
  
  <pre><code>@echo off    
  setLocal DisableDelayedExpansion    
  for /f "tokens=* delims= " %%G in (ConnectionManagement.xml) do (    
      set str=%%G     
      set mydate=%%G    
      echo got-    
      echo %%G    
      echo %mydate%    
      PAUSE
  
      ECHO %mydate%|findstr /R /C:[0-9][0-9][0-9][0-9]\\[0-9][0-9]\\[0-9][0-9] &gt; nul    
      IF ERRORLEVEL 0 goto valueok    
  )
  
  echo DONE    
  PAUSE
  
  goto end    
  
  :valueok    
  echo VALUEOK
  
  :end    
  PAUSE
  </code></pre>
  
  <p>Unfortunately this incorrectly recognised the xml header as a valid date; but I think this is to do with ErrorLevel being reset (?). mydate isn't being set, and it recognises the empty variable mydate as a match (!!??). The output is:</p>
  
  <pre><code>got-    
  &lt;?xml version="1.0" encoding="utf-8"?&gt;    
  ECHO is off.    
  Press any key to continue . . .
  VALUEOK    
  Press any key to continue . . .
  </code></pre>
  
  <p>...</p>
  
  <p>Getting rather desperate for a solution. thanks...</p>