Java tutorial
//package com.java2s; import java.io.File; import java.io.FileFilter; import java.util.List; public class Main { public static void getFileList(final List<File> fileList, final File root, final File[] ignoreList) { final File[] list = root.listFiles(); if (list == null) { return; } for (final File f : list) { if (f.isDirectory() && !isIgnored(ignoreList, f)) { getFileList(fileList, f, ignoreList); } else { String filename = getFileExt(f.getName()); if (filename.equalsIgnoreCase("jpg") || filename.equalsIgnoreCase("png") || filename.equalsIgnoreCase("mp4")) { fileList.add(f); } } } } public static void getFileList(final List<File> fileList, final File root, FileFilter filter) { final File[] list = root.listFiles(filter); if (list == null) { return; } for (final File f : list) { if (f.isDirectory()) { fileList.add(f); getFileList(fileList, f, filter); } else { fileList.add(f); } } } private static boolean isIgnored(File[] ignoreList, File file) { boolean result = false; for (File item : ignoreList) { if (item.getName().equalsIgnoreCase(file.getName())) { result = true; // Log.d(TAG, "Skipping folder: " + file); } } return result; } public static String getFileExt(String fileName) { int index = fileName.lastIndexOf(".") + 1; String ext = fileName.substring(index, fileName.length()); return ext; } }