Here you can find the source of getAllFilesInHierarchy(final String basePath, final FilenameFilter filter)
public static File[] getAllFilesInHierarchy(final String basePath, final FilenameFilter filter) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 005, 2007, 2008 committers of openArchitectureWare and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww . j ava 2s . c o m*/ * committers of openArchitectureWare - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { public static File[] getAllFilesInHierarchy(final String basePath, final FilenameFilter filter) throws IOException { return getAllFiles(new File(basePath), filter); } public static File[] getAllFiles(final File file, final FilenameFilter filter) throws IOException { if (!file.isDirectory()) throw new IOException(file.getPath() + " is not a directory!"); final List<File> returnList = new ArrayList<File>(); getAllFilesInternal(file, filter, returnList); return returnList.toArray(new File[returnList.size()]); } private static void getAllFilesInternal(final File aPath, final FilenameFilter filter, final List<File> fileList) { final File[] allFiles = aPath.listFiles(filter); for (int i = 0; i < allFiles.length; i++) { if (allFiles[i].isDirectory()) getAllFilesInternal(allFiles[i], filter, fileList); else fileList.add(allFiles[i]); } } }