Here you can find the source of getResourcesFromDirectory(final File directory, final Pattern pattern)
private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.util.*; import java.util.regex.Pattern; public class Main { private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern) { final Set<String> retval = new HashSet<String>(); final File[] fileList = directory.listFiles(); for (final File file : fileList) { if (file.isDirectory()) { retval.addAll(getResourcesFromDirectory(file, pattern)); } else { try { final String fileName = file.getCanonicalPath(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { try { retval.add(fileName.substring(0, fileName.lastIndexOf(File.separator))); } catch (StringIndexOutOfBoundsException e1) { //do nothing }/*from www .j av a2 s . c o m*/ } } catch (final IOException e) { throw new Error(e); } } } return retval; } }