Java Folder Read Recursive getFiles(File directory, boolean recursive)

Here you can find the source of getFiles(File directory, boolean recursive)

Description

get Files

License

Open Source License

Declaration

public static List<File> getFiles(File directory, boolean recursive) 

Method Source Code


//package com.java2s;
import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<File> getFiles(File directory, boolean recursive) {
        if (!directory.isDirectory()) {
            throw new AssertionError(directory + " is not a directory!");
        }/* w w  w . j  a va2 s .  c  om*/
        List<File> files = new ArrayList<>();
        for (File f : directory.listFiles()) {
            if (f.isDirectory() && recursive) {
                files.addAll(getFiles(f, recursive));
            } else {
                files.add(f);
            }
        }
        return files;
    }
}

Related

  1. getFiles(File dir, String excludeFiles, boolean includeFiles, boolean includeDirs, boolean recursive, List filelist)
  2. getFiles(File directory, boolean recursive)
  3. getFilesAsArrayListRecursive(String path)
  4. getFilesAsArrayListRecursiveHelper(File f, ArrayList filelist)
  5. getFilesByNameRecursive(Collection filesList, File path, String name)
  6. getFilesForFolder(File folder, boolean recursive)