Here you can find the source of getAllFiles(File dir, Pattern filter)
Parameter | Description |
---|---|
filter | file filter that determines the files to find |
dir | base directory |
public static List<File> getAllFiles(File dir, Pattern filter)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import java.util.regex.Pattern; public class Main { /** jdk1.4 logger */ private static Logger logger = Logger.getLogger("de.axelwernicke.mypod.util"); /**/*from w w w. ja v a2 s . c om*/ * Gets all files below the given directory. * * @param filter file filter that determines the files to find * @param dir base directory * @return all files below the base directory as File objects */ public static List<File> getAllFiles(File dir, Pattern filter) { logger.entering("de.axelwernicke.mypod.util.FileUtils", "getAllFiles"); List<File> allFiles = new ArrayList<File>(); try { // determine all subdirectories File[] files = dir.listFiles(); int fileLength = files.length; for (int i = 0; i < fileLength; i++) { if (files[i].isDirectory()) { allFiles.addAll(getAllFiles(files[i], filter)); } else { if (filter.matcher(files[i].getPath()).matches()) { allFiles.add(files[i]); } } } } catch (Exception e) { logger.warning("exception raised: " + e.getMessage()); e.printStackTrace(); } logger.exiting("de.axelwernicke.mypod.util.FileUtils", "getAllFiles"); return allFiles; } }