title: Recursively finding only directories with FileUtils.listFiles
body: <p>I want to collect a list of <em>all</em> files under a directory, in particular including subdirectories. I like not doing things myself, so I'm using <code>FileUtils.listFiles</code> from Apache Commons IO. So I have something like:</p>
  
  <pre><code>import java.io.File;
  import java.util.Collection;
  
  import org.apache.commons.io.FileUtils;
  import org.apache.commons.io.filefilter.TrueFileFilter;
  
  public class TestListFiles {
    public static void main(String[] args) {
      Collection&lt;File&gt; found = FileUtils.listFiles(new File("foo"),
          TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
      for (File f : found) {
        System.out.println("Found file: " + f);
      }
    }
  }
  </code></pre>
  
  <p>Problem is, this only appears to find normal files, not directories:</p>
  
  <pre><code>$ mkdir -p foo/bar/baz; touch foo/one_file
  $ java -classpath commons-io-1.4.jar:. TestListFiles
  Found file: foo/one_file
  </code></pre>
  
  <p>I'm already passing <code>TrueFileFilter</code> to both of the filters, so I can't think of anything more inclusive. I want it to list: <code>"foo", "foo/one_file", "foo/bar", "foo/bar/baz"</code> (in any order).</p>
  
  <p>I would accept non-<code>FileUtils</code> solutions as well, but it seems silly to have to write my own BFS, or even to collect the set of parent directories from the list I do get. (That would miss empty subdirectories anyway.) This is on Linux, FWIW.</p>