Java Utililty Methods Directory to File List

List of utility methods to do Directory to File List

Description

The list of methods to do Directory to File List are organized into topic(s).

Method

File[]getAllFiles(File directory, boolean hidden)
get All Files
File[] files = directory.listFiles();
List<File> fileLst = new ArrayList<File>();
for (File file : files) {
    File[] fs = getFile(file, hidden);
    for (File f : fs) {
        fileLst.add(f);
return fileLst.toArray(new File[fileLst.size()]);
MapgetAllFiles(File directory, String rootPath)
Search through the directory and find all sub-folders, files and those in its sub-folders recursively.
if (directory == null) {
    throw new NullPointerException("argument 'directory' cannot be null");
if (rootPath == null) {
    throw new NullPointerException("argument 'rootPath' cannot be null");
Map<String, File> returnResult = new HashMap<String, File>();
String fileRootPath = rootPath != null ? rootPath : directory.getAbsolutePath();
...
ListgetAllFiles(File inFileOrDir, boolean recurseDir)
get All Files
final List<File> ret = new LinkedList<File>();
Stack<File> stack = new Stack<File>();
stack.add(inFileOrDir);
while (!stack.isEmpty()) {
    File f = stack.pop();
    if (f.isFile()) {
        ret.add(f);
    } else {
...
ListgetAllFiles(File input)
get All Files
ArrayList<File> a = new ArrayList<>();
if (!input.isDirectory()) {
    a.add(input);
    return a;
for (File f : input.listFiles()) {
    a.addAll(getAllFiles(f));
return a;
voidgetAllFiles(File outputDir, List files)
get All Files
File[] fileList = outputDir.listFiles(new FileFilter() {
    public boolean accept(File pathname) {
        if (pathname.getName().endsWith(".class") || pathname.isDirectory())
            return true;
        return false;
});
for (File file : fileList) {
...
voidgetAllFiles(File path, List fileList, boolean recursive)
Gets all files in a specified path.
if (path.isDirectory()) {
    File[] files = path.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                fileList.add(files[i]);
            } else if (recursive) {
                getAllFiles(files[i], fileList, recursive);
...
File[]getAllFiles(File root, FileFilter fileFilter)
get All Files
ArrayList<File> files = new ArrayList<File>();
if (root.isDirectory()) {
    collectAllFiles(root, files, fileFilter);
    File[] result = new File[files.size()];
    files.toArray(result);
    return result;
return null;
...
SetgetAllFiles(File rootDirectory, FileFilter fileFilter, boolean includeSubdirectories)
get All Files
Set<File> fileSet = Sets.newHashSet();
return getAllFiles(rootDirectory, fileSet, fileFilter, includeSubdirectories);
voidgetAllFiles(File sourceDirectory, List fileList)
Retrieve all the files included in the source directory to be archived
File[] files = sourceDirectory.listFiles();
if (files != null) {
    for (File file : files) {
        fileList.add(file);
        if (file.isDirectory()) {
            getAllFiles(file, fileList);
ListgetAllFiles(final String path, final String suffix, boolean recurse)
Scan the given directory for files containing the substrMatch Small case extensions '.dbf' are recognized and returned as '.DBF'
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
final List<File> list = new ArrayList<File>(20);
String upperSuffix = null;
if (suffix != null)
    upperSuffix = suffix.toUpperCase();
if (listOfFiles != null) {
    for (int i = 0; i < listOfFiles.length; i++) {
...