예제 #1
0
  private static void directoryEntriesInPath(
      List<File> collectedFiles, File parentDir, FileFilter filter) {
    if ((filter == null) || ((filter != null) && (filter.accept(parentDir)))) {
      collectedFiles.add(parentDir);
    }

    File[] files = parentDir.listFiles();
    if (files != null) {
      for (int numFiles = files.length, i = 0; i < numFiles; i++) {
        File currentFile = files[i];

        if ((filter == null) || ((filter != null) && (filter.accept(currentFile)))) {
          collectedFiles.add(currentFile);
        }

        if (currentFile.isDirectory()) {
          FileUtils.directoryEntriesInPath(collectedFiles, currentFile, filter);
        }
      }
    }
  }
예제 #2
0
  /**
   * Recursively collect all Files in the given directory and all its subdirectories, applying the
   * given FileFilter.
   *
   * @param rootDirectory the top level directory used for the search
   * @param filter a FileFilter used for accepting/rejecting individual entries
   * @return a List of found Files
   */
  public static List<File> directoryEntriesInPath(File rootDirectory, FileFilter filter) {
    if (rootDirectory == null) {
      throw new IllegalArgumentException("File must not be null!");
    }

    if (!rootDirectory.exists()) {
      throw new IllegalArgumentException("File does not exist!");
    }

    ArrayList<File> collectedFiles = new ArrayList<File>(32);

    if (rootDirectory.isFile()) {
      if ((filter == null) || ((filter != null) && (filter.accept(rootDirectory)))) {
        collectedFiles.add(rootDirectory);
      }
      return collectedFiles;
    }

    FileUtils.directoryEntriesInPath(collectedFiles, rootDirectory, filter);
    return collectedFiles;
  }
예제 #3
0
 /**
  * Recursively collect all Files in the given directory and all its subdirectories.
  *
  * @param rootDirectory the top level directory used for the search
  * @return a List of found Files
  */
 public static List<File> directoryEntriesInPath(File rootDirectory) {
   return FileUtils.directoryEntriesInPath(rootDirectory, null);
 }