Here you can find the source of getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)
Parameter | Description |
---|---|
parentDir | : the parent directory |
filter | : the files filter |
public static List<File> getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)
//package com.java2s; import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.List; public class Main { /**/*from w ww .ja v a 2 s . c o m*/ * Returns all the files that satisfy the filter criteria wherever (in any replace-directory) they are inside this folder * * @param parentDir : the parent directory * @param filter : the files filter * @return a list of all the available files */ public static List<File> getAllFilesInAllSubDirectories(File parentDir, FileFilter filter) { List<File> filesList = null; return getAllFilesInAllSubDirectories(filesList, parentDir, filter); } /** * Returns all the files that satisfy the filter criteria wherever (in any replace-directory) they are inside this folder * * @param filesList : the list to attach the files into * @param parentDir : the parent directory * @param filter : the files filter * @return a list of all the available files */ public static List<File> getAllFilesInAllSubDirectories(List<File> filesList, File parentDir, FileFilter filter) { if (parentDir == null || !parentDir.exists()) { return filesList; } File[] files = parentDir.listFiles(filter); if (files != null) { for (File vFile : files) { if (filesList == null) { filesList = new ArrayList<>(); } filesList.add(vFile); } } File[] directories = parentDir.listFiles(); if (directories != null) { for (File vDirectory : directories) { filesList = getAllFilesInAllSubDirectories(filesList, vDirectory, filter); } } return filesList; } }