Java Recursive List recursiveListint(List list, File file, FilenameFilter filter)

Here you can find the source of recursiveListint(List list, File file, FilenameFilter filter)

Description

If the parameter file is a file then it is added to the list of files.

License

Apache License

Parameter

Parameter Description
list The list of the files.
file The file that is added to the list of files or a directory whose files will be added to the list.
filter The filter that it is used to filter the files from the directory.

Declaration

private static void recursiveListint(List<File> list, File file, FilenameFilter filter) 

Method Source Code


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

import java.io.File;
import java.io.FilenameFilter;

import java.util.List;

public class Main {
    /**//from  w ww.  j  a  v a 2  s . c  om
     * If the parameter file is a file then it is added to the 
     * list of files. If it is a directory, it adds its contents recursively.
     * In case a filter is provided, the files from the directory have
     * to satisfy that filter. 
     * 
     * @param list
     *       The list of the files.
     * @param file
     *       The file that is added to the list of files or a 
     *       directory whose files will be added to the list.
     * @param filter
     *       The filter that it is used to filter the files 
     *       from the directory.
     *       
     */
    private static void recursiveListint(List<File> list, File file, FilenameFilter filter) {
        if (file.isFile()) {
            list.add(file);
        } else {
            File[] children = null;
            if (filter != null) {
                children = file.listFiles(filter);
            } else {
                children = file.listFiles();
            }

            for (File child : children) {
                if (child.isFile()) {
                    list.add(child);
                } else {
                    recursiveListint(list, child, filter);
                }
            }
        }
    }
}

Related

  1. recursiveListFiles(File baseDir, final FileFilter filter)
  2. recursiveListFiles(File dir, FileFilter filter)
  3. recursiveListFiles(File file, List files)
  4. recursiveListFiles(String path)
  5. recursiveListFilesHelper(File dir, FileFilter filter, List fileList)
  6. recursiveListPartialPaths(File parent, boolean includeDirs)