title: Fast listing files in a directory and all of its subdirectories
body: <p>I need to find all files in a directory and all of its subdirectories (except some).<br>
  Currently I'm using this method:</p>
  
  <pre><code>public  static Collection&lt;File&gt; listFiles(File directory,FilenameFilter filter,boolean recurse){
      Vector&lt;File&gt; files = new Vector&lt;File&gt;();
      File[] entries = directory.listFiles();
      if(entries!=null){
          for (File entry : entries){
              if (filter == null || filter.accept(directory, entry.getName())){
                      files.add(entry);
              }
  
              if (recurse &amp;&amp; entry.isDirectory()){
                      files.addAll(listFiles(entry, filter, recurse));
              }
          }
      }
      return files;
  }
  </code></pre>
  
  <p>and using it like this:  </p>
  
  <pre><code>        this.foundFiles=listFiles(new File(this.BaseDirectory), new FilenameFilter() {
              public boolean accept(File dir, String name) {
                  boolean res=true;
                  if(name.endsWith(".pdf")){
                      if(!dir.getPath().endsWith("done")){
                          if((workingFile!=null &amp;&amp; (dir.getPath().equals(workingFile.getParent()) &amp;&amp; name.equals(workingFile.getName())))){
                              res=false;
                          }else{
                              try {
                                  ArrayList&lt;String&gt; AuthFolders = DB.getGroupAuthFoldersArray();
                                  for(String folder:AuthFolders){
                                      if(dir.getPath().startsWith(BaseDirectory+File.separator+folder)){
                                          res=true;
                                          break;
                                      }else{
                                          res=false;
                                      }
                                  }
                              } catch (SQLException ex) {
                                  Logger.getLogger(scanner.class.getName()).log(Level.SEVERE, null, ex);
                                  res=false;
                              } catch (InterruptedException ex) {
                                  Logger.getLogger(scanner.class.getName()).log(Level.SEVERE, null, ex);
                                  res=false;
                              }
                          }
                      }else{
                          res=false;
                      }
                  }else{
                      res=false;
                  }
                  return res;
              }
          }, true);
  </code></pre>
  
  <p>But this is too slow! I have about 3000 files in the directory and it takes 10-15 mins (!!) for this method to find them all.  </p>
  
  <p>How Can I do this fast?<br>
  I'm thinking about using <code>org.apache.commons.io.FileUtils.listfiles</code> method.  Is there a faster way?</p>
  
  <p>Thanks  </p>