title: Batch File To Delete Folders Not Contained In a List
body: <p>I have a group of folders that I would like to keep and would like to delete the rest.  I have a .txt file that contains the names of the folders that I would like to keep.</p>
  
  <p>So here is what I have:</p>
  
  <p>In <code>C:\test</code> I have the following folders:</p>
  
  <pre><code>AAA
  BBB
  CCC
  DDD
  EEE
  </code></pre>
  
  <p>In my text file <code>exclude.txt</code> I have listed the following folder names:</p>
  
  <pre><code>AAA
  BBB
  CCC
  </code></pre>
  
  <p>Thus, I would like my end product to be that <code>C:\test</code> should only have the folders <code>AAA</code>, <code>BBB</code>, and <code>CCC</code> after the batch file.</p>
  
  <p>Here is what I have so far but not having any luck:</p>
  
  <pre><code>for /d %%a in ("C:\test\*") do findstr /i /x /c:"%%~nxa" exclude.txt || rd /s /q %%a
  </code></pre>