Here you can find the source of deepListFiles(File dir, FileFilter filter)
Parameter | Description |
---|---|
dir | the directory to explore |
filter | the FileFilter to use (may be null) |
public static List<File> deepListFiles(File dir, FileFilter filter)
//package com.java2s; /*/*from w ww . j ava2 s .co m*/ GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License */ import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.List; public class Main { /** * Return a list of files from the given directory and matching the given * filter. If a filter is provided, the directories (and their content) that * do not match the filter are skipped. * * @param dir * the directory to explore * @param filter * the FileFilter to use (may be null) * @return a List of java.io.File * @see #deepListFiles(File, FileFilter, boolean) */ public static List<File> deepListFiles(File dir, FileFilter filter) { return deepListFiles(dir, filter, true); } /** * Return a list of files from the given directory and matching the given * filter. * * @param dir * the directory to explore * @param filter * the FileFilter to use (may be null) * @param checkDir * if true the directories that do not match the filter are skipped. * @return a List of java.io.File */ public static List<File> deepListFiles(File dir, FileFilter filter, boolean checkDir) { ArrayList<File> list = new ArrayList<File>(); deepListFilesVisitor(dir, filter, checkDir, list); return list; } private static void deepListFilesVisitor(File file, FileFilter filter, boolean checkDir, List<File> list) { if (file.isDirectory()) { if (checkDir && filter != null && !filter.accept(file)) { return; } File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { deepListFilesVisitor(files[i], filter, checkDir, list); } } else { if (filter == null || filter.accept(file)) { list.add(file); } } } }