title: Batch %errorlevel% returns 0 in FOR loop
body: <p>I am trying to make a loop that will go through a set of text files in specified directory searching for a string. The result is reported based on whether the string is found. But the <code>%errorlevel%</code> always returns 0 and evaluates to 0.</p>
  
  <pre><code>SETLOCAL enabledelayedexpansion
  
      FOR %%G IN (*.txt) DO (
          find /i "My text string" "%%G"
          ECHO %date% %time% :  errorlevel is %errorlevel% &gt;&gt; %report_dir%\%computername%.txt
          IF %errorlevel% EQU 1 (
              ECHO %date% %time% : String found &gt;&gt; %report_dir%\%computername%.txt
  
              GOTO:copy_log
          )
  
      )
  
      ENDLOCAL
  </code></pre>
  
  <p>Raymond did you mean that?:</p>
  
  <pre><code>SETLOCAL enabledelayedexpansion
  
      FOR %%G IN (*.txt) DO (
          find /i "My text string" "%%G"
          IF %errorlevel% (
              ECHO %date% %time% : String found &gt;&gt; %report_dir%\%computername%.txt
  
              GOTO:copy_log
          )
  
      )
  
      ENDLOCAL
  </code></pre>