title: Batch Script to find string in directory and all subdirectories
body: <p>I want to write a batch file which used the find command to find a string in the parent directory and all sub directories, and prints that output to a text file, then opens the text file when done. My code so far looks like this:</p>
  
  <pre><code>@echo off
  set /p "var1= Enter the String to Find: "
  for /F "delims=" %a in ('dir /B /S *.txt') do @(find /i "%var1" "%a" 1&gt;nul 2&gt;&amp;1 &amp;&amp; find /i "%var1" "%a") &gt;&gt; result.txt
  start result.txt
  </code></pre>
  
  <p>But this is currently not even writing anything to result.txt, even though I am sure that where I am searching the string appears in multiple .txt files. I know it must be something syntax-wise but I can't seem to figure it out.</p>