Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static List<String> getFiles(String aDirPath, Boolean aIsGetRelativePath, boolean aIsContainSubDir, FilenameFilter aFilenameFilter) { List<String> aOutList = new ArrayList<String>(); File dirPath = new File(aDirPath); getFiles(dirPath, aIsGetRelativePath, dirPath, aIsContainSubDir, aFilenameFilter, aOutList); return aOutList; } private static void getFiles(File aRootDir, Boolean aIsGetRelativePath, File aDirPath, boolean aIsContainSubDir, FilenameFilter aFilenameFilter, Collection<String> aOutList) { if (aOutList == null) { aOutList = new ArrayList<String>(); } File[] files = aDirPath.listFiles(aFilenameFilter); for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.isFile()) { String strPath = f.getPath(); if (aRootDir != null && aIsGetRelativePath) { strPath = strPath.substring(aRootDir.getPath().length()); } aOutList.add(strPath); if (!aIsContainSubDir) break; } else if (f.isDirectory() && f.getPath().indexOf("/.") == -1) getFiles(aRootDir, aIsGetRelativePath, f, aIsContainSubDir, aFilenameFilter, aOutList); } } }