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

ListgetAllFiles(String zipName, String fileNameRegEx)
Reads zip file, returns a list of all entries that match the given regular expression
List<ZipEntry> Matching = new ArrayList<ZipEntry>();
Pattern p;
Matcher m;
p = Pattern.compile(fileNameRegEx);
m = p.matcher("");
ZipFile Zip = null;
try {
    Zip = new ZipFile(zipName);
...
ListgetAllFiles(String[] args, boolean recurse)
Get all files from the given location(s).
return getAllFiles(args, recurse, "");
ListgetAllFilesByExtension(String path, String extension)
get All Files By Extension
List<File> files = new ArrayList<File>();
final File folder = new File(path);
for (final File fileEntry : folder.listFiles()) {
    if (!fileEntry.isDirectory() && fileEntry.getName().endsWith(extension)) {
        files.add(fileEntry);
return files;
...
voidgetAllFilesByProfix(String path, String suffix, List files)
get All Files By Profix
File file = new File(path);
if (file.isDirectory()) {
    File[] fs = file.listFiles();
    if (fs != null) {
        for (File file2 : fs) {
            if (file2.isDirectory()) {
                getAllFilesByProfix(file2.getPath(), suffix, files);
            } else {
...
File[]getAllFilesEndingWith(String path, final String extension)
Return an array of File objects ending with given extension
File rootDirectory = new File(path);
return rootDirectory.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith(extension);
});
ArrayListgetAllFilesEndingWith(String path, final String extension)
get All Files Ending With
File directory = new File(path);
ArrayList<File> files = new ArrayList<File>(Arrays.asList(directory.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
        return name.endsWith(extension);
})));
return files;
...
File[]getAllFilesForType(File dir, FilenameFilter filter)
get All Files For Type
return dir.listFiles(filter);
ListgetAllFilesFromDir(File dir)
Gets the all files from directory.
final List<File> foundedFileList = new ArrayList<>();
final File[] children = dir.getAbsoluteFile().listFiles();
if (children == null || children.length < 1) {
    return foundedFileList;
for (File child : children) {
    if (!child.isDirectory()) {
        foundedFileList.add(child.getAbsoluteFile());
...
ListgetAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter)
DOC xqliu Comment method "getAllFilesFromFolder".
List<File> files = new ArrayList<File>();
getAllFilesFromFolder(aFolder, files, filenameFilter);
return files;
voidgetAllFilesFromFolder(File sampleFolder, ArrayList fileList, FilenameFilter filenameFilter)
DOC sgandon Comment method "getAllFilesFromFolder".
File[] folderFiles = sampleFolder.listFiles(filenameFilter);
Collections.addAll(fileList, folderFiles);
File[] allFolders = sampleFolder.listFiles(new FileFilter() {
    public boolean accept(File arg0) {
        return arg0.isDirectory();
});
for (File folder : allFolders) {
...