Java Folder Read by Filter getFilesUnder(String path, FileFilter fileFilter)

Here you can find the source of getFilesUnder(String path, FileFilter fileFilter)

Description

get Files Under

License

Open Source License

Declaration

public static List<File> getFilesUnder(String path, FileFilter fileFilter) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.util.*;

public class Main {
    public static List<File> getFilesUnder(String path, FileFilter fileFilter) {
        File root = new File(path);
        List<File> files = new ArrayList<File>();
        addFilesUnder(root, files, fileFilter);
        return files;
    }//from  w  w w  .j  a v  a  2 s  .c  om

    private static void addFilesUnder(File root, List<File> files, FileFilter fileFilter) {
        if (!fileFilter.accept(root))
            return;
        if (root.isFile()) {
            files.add(root);
            return;
        }
        if (root.isDirectory()) {
            File[] children = root.listFiles();
            for (int i = 0; i < children.length; i++) {
                File child = children[i];
                addFilesUnder(child, files, fileFilter);
            }
        }
    }
}

Related

  1. getFiles(String name, FileFilter filter, boolean includeSubtree)
  2. getFiles(String sourceDirPath, FilenameFilter filter, Comparator comparator)
  3. getFiles(String sourceName, FilenameFilter filter)
  4. getFilesOnlyFilter()
  5. getFilesRealWorking(File aStartingDir, FilenameFilter filter)
  6. getFilesWithFilter(String DirectoryName, FilenameFilter Filter)