Java File Find find(File path, Boolean recursive)

Here you can find the source of find(File path, Boolean recursive)

Description

Return all files beneath path.

License

Open Source License

Parameter

Parameter Description
path the path to search
recursive iff true, search subdirectories too.

Declaration

public static ArrayList<File> find(File path, Boolean recursive) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.util.*;

public class Main {
    /***//  w w  w .  j a v  a  2s. co  m
     * Return all files beneath path.
     * @param path the path to search
     * @param recursive iff true, search subdirectories too.
     * @return
     */
    public static ArrayList<File> find(File path, Boolean recursive) {
        ArrayList<File> files = new ArrayList<File>();
        find(files, path, recursive);
        return files;
    }

    /***
     * A private helper function for building the results for public Find.
     * @param files
     * @param path
     * @param recursive
     */
    private static void find(List<File> files, File path, Boolean recursive) {
        if (path.isDirectory()) {
            // iterate over files
            for (File file : path.listFiles()) {
                if (recursive || !file.isDirectory()) {
                    find(files, file, recursive);
                }
            }
        } else {
            // process the file
            files.add(path);
        }
    }
}

Related

  1. find(File dir, String baseName)
  2. find(File dir, String suffix, Set ignore)
  3. find(File file)
  4. find(File file, Pattern pattern, int limit, List found, Set visited)
  5. find(File folder, final String name)
  6. find(File root)
  7. find(final File fileDir, final String fileNameRegex)
  8. find(final File root, final String name)
  9. find(String _sSourceString, String _sReg, int group)