title: Batch script to execute in every subdirectories
body: <p>I have multiple text files inside subdirectories. i want to delete all text files, but keep only one random text file.</p>
  <pre><code>C:\Main\abc\file1.txt
  C:\Main\abc\file2.txt
  C:\Main\abe\file1.txt
  C:\Main\abe\file2.txt
  </code></pre>
  <p>Output</p>
  <pre><code>C:\Main\abc\file1.txt
  C:\Main\abe\file2.txt
  </code></pre>
  <p>this script is working, but I could not able to execute for all subdirectories</p>
  <pre><code>For /f &quot;skip=1 eol=: delims=&quot; %%F in ('dir /b /o-d *.txt') do @del &quot;%%F&quot;
  </code></pre>
  <p>I tried this</p>
  <pre><code>FOR /R &quot;C:\Main&quot; %%F IN (.) DO (
  For /f &quot;skip=1 eol=: delims=&quot; %%F in ('dir /b /o-d *.txt') do @del &quot;%%F&quot;
  )
  pause
  </code></pre>
  <p>but the script does not read subfolders. can someone please guide me on where am I doing it wrong?</p>