Java Recursive List recursiveListFiles(File dir, FileFilter filter)

Here you can find the source of recursiveListFiles(File dir, FileFilter filter)

Description

recursive List Files

License

Apache License

Declaration

public static File[] recursiveListFiles(File dir, FileFilter filter) 

Method Source Code


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

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static File[] recursiveListFiles(File dir, FileFilter filter) {
        if (!dir.isDirectory())
            throw new IllegalArgumentException(dir + " is not a directory");
        List<File> fileList = new ArrayList<File>();
        recursiveListFilesHelper(dir, filter, fileList);
        return fileList.toArray(new File[fileList.size()]);
    }//from w  w  w  . j a va  2 s.c om

    public static void recursiveListFilesHelper(File dir, FileFilter filter, List<File> fileList) {
        for (File f : dir.listFiles()) {
            if (f.isDirectory()) {
                recursiveListFilesHelper(f, filter, fileList);
            } else {
                if (filter.accept(f))
                    fileList.add(f);
            }
        }
    }
}

Related

  1. recursiveList(File dir, FilenameFilter filter)
  2. recursiveListFile(File folder)
  3. recursiveListFiles(File baseDir, final FileFilter filter)
  4. recursiveListFiles(File file, List files)
  5. recursiveListFiles(String path)
  6. recursiveListFilesHelper(File dir, FileFilter filter, List fileList)
  7. recursiveListint(List list, File file, FilenameFilter filter)