title: Exiting Recursive function searching subdirectories
body: <p>I'm trying to get a list of all subdirectories in a given directory recursively, because the existing command apparently isn't good enough.
  I can successfully get the directories, but can't seem to leave the recursive algorithm. I'm sure there's bound to be an easy way of doing it that I'm not seeing. Any help would be great!</p>
  
  <pre><code>public static public void directorySearch(ref List&lt;DirectoryInfo&gt; subs, ref DirectoryInfo dir, ref List&lt;FileInfo&gt; fileEntries, ref int k)
  {
    do
      {
        foreach (DirectoryInfo elements in dir.GetDirectories())
        {
          subs.Add(elements);
        }
        k++;
        DirectoryInfo fi = subs[k];
        directorySearch(ref subs, ref fi, ref fileEntries, ref k);
      } while (??????);
        //This will be used once function is working to get files in all directories
          /*
        foreach (FileInfo f in dir.GetFiles()
        {
            fileEntries.Add(f);
        }*/
  }
  </code></pre>