Java Directory to File List getAllFiles(File path, List fileList, boolean recursive)

Here you can find the source of getAllFiles(File path, List fileList, boolean recursive)

Description

Gets all files in a specified path.

License

Open Source License

Parameter

Parameter Description
path absolute path of a folder
fileList a list to collect the files
recursive if <code>true</code>, find the files in sub folders as well

Declaration

public static void getAllFiles(File path, List<File> fileList, boolean recursive) 

Method Source Code

//package com.java2s;
// are made available under the terms of the Eclipse Public License v1.0

import java.io.File;

import java.util.List;

public class Main {
    /**/*from www .  ja va  2  s . c o  m*/
     * Gets all files in a specified path.
     * 
     * @param path
     *            absolute path of a folder
     * @param fileList
     *            a list to collect the files
     * @param recursive
     *            if <code>true</code>, find the files in sub folders as well
     */
    public static void getAllFiles(File path, List<File> fileList, boolean recursive) {
        if (path.isDirectory()) {
            File[] files = path.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isFile()) {
                        fileList.add(files[i]);
                    } else if (recursive) {
                        getAllFiles(files[i], fileList, recursive);
                    }
                }
            }
        }
    }
}

Related

  1. getAllFiles(File directory, boolean hidden)
  2. getAllFiles(File directory, String rootPath)
  3. getAllFiles(File inFileOrDir, boolean recurseDir)
  4. getAllFiles(File input)
  5. getAllFiles(File outputDir, List files)
  6. getAllFiles(File root, FileFilter fileFilter)
  7. getAllFiles(File rootDirectory, FileFilter fileFilter, boolean includeSubdirectories)
  8. getAllFiles(File sourceDirectory, List fileList)
  9. getAllFiles(final String path, final String suffix, boolean recurse)