Java Directory to File List getAllFiles(File directory)

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

Description

Collects all non-directory files in the given input directory (recursively).

License

Creative Commons License

Parameter

Parameter Description
directory Input directory.

Return

All non-directory files, recursively.

Declaration

public static Collection<File> getAllFiles(File directory) 

Method Source Code

//package com.java2s;
/** //from  w ww.ja v  a  2s  . com
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License 
(see http://creativecommons.org/licenses/by/3.0) by 
the YAGO-NAGA team (see http://mpii.de/yago-naga)
    
Some utility methods for arrays
*/

import java.io.File;

import java.util.Collection;
import java.util.LinkedList;

public class Main {
    /**
     * Collects all non-directory files in the given input directory 
     * (recursively).
     * 
     * @param directory Input directory.
     * @return          All non-directory files, recursively.
     */
    public static Collection<File> getAllFiles(File directory) {
        Collection<File> files = new LinkedList<File>();
        getAllFilesRecursively(directory, files);
        return files;
    }

    /**
     * Helper for getAllSubdirectories(directory).
     */
    private static void getAllFilesRecursively(File directory, Collection<File> files) {

        for (File file : directory.listFiles()) {
            if (file.isDirectory()) {
                getAllFilesRecursively(file, files);
            } else {
                files.add(file);
            }
        }
    }
}

Related

  1. getAllFiles(File dir)
  2. getAllFiles(File dir, List fileList)
  3. getAllFiles(File dir, List fileList)
  4. getAllFiles(File dir, Pattern filter)
  5. getAllFiles(File directory)
  6. getAllFiles(File directory, boolean hidden)
  7. getAllFiles(File directory, String rootPath)
  8. getAllFiles(File inFileOrDir, boolean recurseDir)
  9. getAllFiles(File input)