title: Exclude multiple folders with Dir command
body: <p>I had search thru the forum with excluding multiple files while using DIR command. But didn't find what i really needed. Some are even with PHP or VBS, really don't know how they works.</p>
  
  <p>What I'm trying to do is <em>*DIR*ing</em> all profile folders and also excluding certain default folders, this is a part of showing what and how many users are having profiles on that computer.</p>
  
  <p>I will explain a bit more because i may not fully be understood what my needs are.</p>
  
  <p>If i use the <em>DIR</em> without <em>findstr</em>.</p>
  
  <pre><code>DIR /A:d /B "F:\Documents and Settings"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Administrator
  All Users
  Default User
  LocalService
  userprofile1
  NetworkService
  userprofile2
  ...
  userprofileN
  </code></pre>
  
  <p>But my actual needs are:</p>
  
  <pre><code>userprofile1
  userprofile2
  ...
  userprofileN
  </code></pre>
  
  <p>I also got this far with my script now.</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEDELAYEDEXPANSION
  IF ERRORLEVEL 1 ECHO Your OS does not support enable extensions
  DIR /A:d /B "F:\Documents and Settings" | findstr /v "Admin" | findstr /v "Default" | findstr /v "LocalService" | findstr /v "NetworkService"
  EXIT
  </code></pre>
  
  <p>My above script actually works but is fixed and may not be pretty coded.
  I would ask about is it possible to use a <em>For</em> loop to shorten the long <em>findstr</em> pipes and set a variable that contains the folder names to exclude ?
  I prefer to use a variable instead of a text files that contains folders to exclude.</p>
  
  <p>I came up with below but it duplicates the ouput:</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEDELAYEDEXPANSION
  IF ERRORLEVEL 1 ECHO Your OS does not support enable extensions
  SET xUser="Admin" "Default" "hi_I_will_be_future_added"
  FOR %%A IN (!Xuser!) DO ( 
   DIR /A:d /B "F:\Documents and Settings" | findstr /v %%A
  )
  </code></pre>
  
  <p>Thank you to this great forum and for all that may had helped both me and others.</p>