title: How to find folders that contain files with a given extension
body: <p>I am a novice and have seen that System.IO may provide what I need but I can't work out how. I'm using <strong>VB.net</strong></p>
  <p>Starting at a given folder e.g. <strong>C:\StartHere</strong> I want to recurse down the folder hierarchy looking for any folders that contain files with a given extension e.g. *<strong>.exe</strong>. I want to build a list of those folders for subsequent processing.</p>
  <p>I would be very grateful if someone could give help as I don't know the best way to approach this.</p>
  <p><strong>UPDATE</strong></p>
  <p>The following provides more details as requested by Andrew Morton.
  Starting from a specified folder, I want to get a list containing the full paths to all sub-folders that contain EXEs. So presented with the following folders…</p>
  <pre><code>C:\StartHere\folderA (contains some EXEs)
  C:\StartHere\folderB (none in here)
  C:\StartHere\Deeper\DeepC (contains some EXEs)
  C:\StartHere\Deeper\DeepD (contains some EXEs)
  C:\StartHere\Deeper\DeepE (none in here)
  C:\StartHere\Deeper\DeepF (contains some EXEs)
  </code></pre>
  <p>The code would result in a list containing:</p>
  <pre><code>C:\StartHere\folderA 
  C:\StartHere\Deeper\DeepC
  C:\StartHere\Deeper\DeepD
  C:\StartHere\Deeper\DeepF
  </code></pre>
  <p>The code that I now have follow the great help from @Tim Schmelter, @Jimi and @Andrew Morton is this:</p>
  <pre><code>Dim folderList = Directory.EnumerateDirectories(&quot;C:\StartHere&quot;, &quot;*&quot;, SearchOption.AllDirectories).Where(Function(d) Directory.EnumerateFiles(d, &quot;*.exe&quot;).Any()).Select(Function(f) Path.GetDirectoryName(f))
  </code></pre>
  <p>When run, it creates the following list; so it has found the right folders but is adding their parent folder to the list rather than the full path:</p>
  <pre><code>C:\StartHere 
  C:\StartHere\Deeper
  C:\StartHere\Deeper
  C:\StartHere\Deeper
  </code></pre>