Java Directory to File List getAllFiles(File dir)

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

Description

get All Files

License

Open Source License

Declaration

public static List<File> getAllFiles(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> getAllFiles(File dir) {
        List<File> result = new ArrayList<>();
        getAllFilesAux(dir, result);//  ww  w. j  ava 2s .  co  m
        return result;
    }

    private static void getAllFilesAux(File dir, List<File> result) {
        File[] files = dir.listFiles();
        if (files == null) {
            return;
        }
        for (File file : files) {
            if (file.isDirectory()) {
                getAllFilesAux(file, result);
            } else if (file.isFile()) {
                result.add(file);
            }
        }
    }
}

Related

  1. getAllFileNames(String path, String suffix, boolean isDepth)
  2. getAllFileNamesByPath(String path)
  3. getAllFileNamesInDir(String folderName)
  4. getAllFileNamesWithExtension(String directory, final String extension)
  5. getAllFilePath(String filedir)
  6. getAllFiles(File dir)
  7. getAllFiles(File dir, List fileList)
  8. getAllFiles(File dir, List fileList)
  9. getAllFiles(File dir, Pattern filter)