Java Folder Read by Filter getFiles(File folder, FilenameFilter filter)

Here you can find the source of getFiles(File folder, FilenameFilter filter)

Description

get Files

License

Open Source License

Declaration

public static List<File> getFiles(File folder, FilenameFilter filter) 

Method Source Code


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

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<File> getFiles(File folder, FilenameFilter filter) {
        return getFiles(folder, filter, true);
    }//from   w w  w.j  a v a 2s  .c o  m

    public static List<File> getFiles(File folder, FilenameFilter filter, Boolean recursive) {
        List<File> files = new ArrayList<File>();
        if (folder.isDirectory()) {
            for (File file : folder.listFiles(filter)) {
                if (file.isDirectory()) {
                    files.addAll(getFiles(file, filter, recursive));
                } else {
                    files.add(file);
                }
            }

        }
        return files;
    }
}

Related

  1. getFiles(File dir, FilenameFilter filter)
  2. getFiles(File root, boolean recurse, FileFilter fileFilter)
  3. getFiles(final File directory, final FilenameFilter filter)
  4. getFiles(String name, FileFilter filter, boolean includeSubtree)
  5. getFiles(String sourceDirPath, FilenameFilter filter, Comparator comparator)