Java Folder Read getFilesIncludeSubdirectories(final File directory)

Here you can find the source of getFilesIncludeSubdirectories(final File directory)

Description

Get all files in directory and all subdirectories.

License

LGPL

Parameter

Parameter Description
directory File, directory

Return

List, list of all files

Declaration

public static List<File> getFilesIncludeSubdirectories(final File directory) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*w ww. jav  a 2 s  .co  m*/
     * Get all files in directory and all subdirectories.
     * 
     * @param directory
     *            File, directory
     * @return List, list of all files
     */
    public static List<File> getFilesIncludeSubdirectories(final File directory) {
        List<File> result = new ArrayList<File>();
        getFilesIncludeSubdirectories(directory, result);
        return result;
    }

    /**
     * Get all files in directory and all subdirectories.
     * 
     * @param directory
     *            File, directory to search
     * @param list
     *            List, list to store found files
     */
    private static void getFilesIncludeSubdirectories(final File directory, List<File> list) {
        File[] fileList = directory.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            list.add(fileList[i]);
            if (fileList[i].isDirectory()) {
                getFilesIncludeSubdirectories(fileList[i], list);
            }
        }
    }
}

Related

  1. getFilesForPattern(String pathToScan, String startWith, String endsWith)
  2. getFilesFromClassPath(String classpath)
  3. getFilesFromDiskWorker(File folderToLoad, final String searchPattern, final boolean justFolders)
  4. getFileSimpleName(final File f)
  5. getFilesInClassPath(String path, String endsWith)
  6. getFilesInFolder(File dir)
  7. getFilesInFolder(final String pathToFolder, final String suffix)
  8. getFilesInFolderByRegex(File folder, final String regex)
  9. getFilesMatchingRegexp(final File directory, final String regexp)