Java Directory to File List getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)

Here you can find the source of getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)

Description

Returns all the files that satisfy the filter criteria wherever (in any replace-directory) they are inside this folder

License

Open Source License

Parameter

Parameter Description
parentDir : the parent directory
filter : the files filter

Return

a list of all the available files

Declaration

public static List<File> getAllFilesInAllSubDirectories(File parentDir, FileFilter filter) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileFilter;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from  w  ww .ja  v a 2 s  . c o  m*/
     * Returns all the files that satisfy the filter criteria wherever (in any replace-directory) they are inside this folder
     *
     * @param parentDir : the parent directory
     * @param filter    : the files filter
     * @return a list of all the available files
     */
    public static List<File> getAllFilesInAllSubDirectories(File parentDir, FileFilter filter) {
        List<File> filesList = null;
        return getAllFilesInAllSubDirectories(filesList, parentDir, filter);
    }

    /**
     * Returns all the files that satisfy the filter criteria wherever (in any replace-directory) they are inside this folder
     *
     * @param filesList : the list to attach the files into
     * @param parentDir : the parent directory
     * @param filter    : the files filter
     * @return a list of all the available files
     */
    public static List<File> getAllFilesInAllSubDirectories(List<File> filesList, File parentDir,
            FileFilter filter) {
        if (parentDir == null || !parentDir.exists()) {
            return filesList;
        }
        File[] files = parentDir.listFiles(filter);
        if (files != null) {
            for (File vFile : files) {
                if (filesList == null) {
                    filesList = new ArrayList<>();
                }
                filesList.add(vFile);
            }
        }
        File[] directories = parentDir.listFiles();
        if (directories != null) {
            for (File vDirectory : directories) {
                filesList = getAllFilesInAllSubDirectories(filesList, vDirectory, filter);
            }
        }
        return filesList;
    }
}

Related

  1. getAllFilesForType(File dir, FilenameFilter filter)
  2. getAllFilesFromDir(File dir)
  3. getAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter)
  4. getAllFilesFromFolder(File sampleFolder, ArrayList fileList, FilenameFilter filenameFilter)
  5. getAllFilesIn(File dir, final String type)
  6. getAllFilesInDir(boolean traverseSubDirs, File dir, boolean includeHidden, String prefix)
  7. getAllFilesInDirectory(File dir)
  8. getAllFilesInDirectory(File directory, List files)
  9. getAllFilesInDirectory(String directoryPath)