Java Utililty Methods Folder Read Recursive

List of utility methods to do Folder Read Recursive

Description

The list of methods to do Folder Read Recursive are organized into topic(s).

Method

ListgetFiles(File dir, String excludeFiles, boolean includeFiles, boolean includeDirs, boolean recursive, List filelist)
Recursive function to descend into the directory tree and find all the files and directories excluding those specified by exclude.
File listFile[] = dir.listFiles();
if (listFile != null) {
    for (int i = 0; i < listFile.length; i++) {
        if (!excludeFile(listFile[i].getName(), excludeFiles)) {
            if (listFile[i].isDirectory()) {
                if (includeDirs) {
                    filelist.add(listFile[i]);
                if (recursive) {
                    filelist = getFiles(listFile[i], excludeFiles, includeFiles, includeDirs, recursive,
                            filelist);
            } else {
                if (includeFiles)
                    filelist.add(listFile[i]);
return filelist;
ListgetFiles(File directory, boolean recursive)
Get all files in a directory
List<File> fileList = new ArrayList<File>();
if (!directory.isDirectory()) { 
    fileList.add(directory);
    return fileList;
File[] files = directory.listFiles();
for (File f : files) {
    if (f.isDirectory()) {
...
ListgetFiles(File directory, boolean recursive)
get Files
if (!directory.isDirectory()) {
    throw new AssertionError(directory + " is not a directory!");
List<File> files = new ArrayList<>();
for (File f : directory.listFiles()) {
    if (f.isDirectory() && recursive) {
        files.addAll(getFiles(f, recursive));
    } else {
...
ArrayListgetFilesAsArrayListRecursive(String path)
get Files As Array List Recursive
ArrayList<String> mFileList = new ArrayList<String>();
File root = new File(path);
getFilesAsArrayListRecursiveHelper(root, mFileList);
return mFileList;
voidgetFilesAsArrayListRecursiveHelper(File f, ArrayList filelist)
get Files As Array List Recursive Helper
if (f.isDirectory()) {
    File[] childs = f.listFiles();
    for (File child : childs) {
        getFilesAsArrayListRecursiveHelper(child, filelist);
    return;
filelist.add(f.getAbsolutePath());
...
voidgetFilesByNameRecursive(Collection filesList, File path, String name)
Get all files existing in the path with the specified name.
for (final File file : path.listFiles()) {
    if (file.isFile() && file.getName().equals(name)) {
        filesList.add(file);
    } else if (file.isDirectory()) {
        getFilesByNameRecursive(filesList, file, name);
ListgetFilesForFolder(File folder, boolean recursive)
Returns a sorted list of files contained in the directory.
List<File> fileList = new ArrayList<File>();
listFilesForFolder(fileList, folder, recursive);
Collections.sort(fileList);
return fileList;
File[]getFilesParent(File dir, String excludeFiles, boolean includeParentDir, boolean includeFiles, boolean includeDirs, boolean recursive)
This is the initial parent to getFiles.
File[] files = null;
List<File> filelist = new ArrayList<File>();
filelist = getFiles(dir, excludeFiles, includeFiles, includeDirs, recursive, filelist);
if (includeParentDir) {
    files = new File[filelist.size() + 1];
    files[0] = dir;
    for (int i = 0; i < filelist.size(); i++) {
        files[i + 1] = filelist.get(i);
...