title: How to use findstr within a loop?
body: <p>I am trying to read the filename and according to the filename set the <code>Output</code> variable.</p>
  
  <p>I have tried using <code>findstr</code> directly on <code>%%F (findstr /i "M002" %%F &gt;nul 2&gt;&amp;1 )</code> and also writing to a temp text file (as below) to test and read it, but nothing worked.</p>
  
  <p>What I'm doing wrong?</p>
  
  <p>P.S. If I remove this out from the loop the code works, but I need it within the loop due to the last line.</p>
  
  <pre><code>rem ===========================================
  
  set FileType=pdf
  
  for %%F in (%~dp0*.%FileType%) do (
    rem ECHO %%F
  
    echo "%%F" &gt; test.txt
    findstr /i "M002" test.txt &gt;nul 2&gt;&amp;1
    echo %errorlevel%
    if not %errorlevel% == 0 (
        echo "4pp"
        echo %%F
        set Output=4PP
    ) ELSE (
        echo "Letter"
        echo %%F
        set Output=Letter
    )
  
    set NetComm="XYZ" "%Output%" etc etc etc
  )
  
  rem ====================================
  </code></pre>