Java Directory to File List getAllFilesInDirectory(File dir)

Here you can find the source of getAllFilesInDirectory(File dir)

Description

get All Files In Directory

License

Open Source License

Declaration

public static List<File> getAllFilesInDirectory(File dir) 

Method Source Code


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

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

public class Main {
    public static List<File> getAllFilesInDirectory(File dir) {
        return getAllFilesInDirectory(dir, true);
    }//from   w w w  .ja va2  s  . c o  m

    public static List<File> getAllFilesInDirectory(File dir, boolean recursive) {
        List<File> files = new ArrayList<>();
        if (dir == null)
            return files;
        File[] fileArr = dir.listFiles();
        if (fileArr == null)
            return files;
        for (File f : fileArr) {
            files.add(f);
            if (recursive) {
                if (f.isDirectory())
                    files.addAll(getAllFilesInDirectory(f));
            }

        }
        return files;
    }
}

Related

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