Here you can find the source of getAllFiles(String dir, String filePattern)
public static String[] getAllFiles(String dir, String filePattern)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FilenameFilter; import java.util.regex.Pattern; public class Main { public static String[] getAllFiles(String dir, String filePattern) { File fd = new File(dir); if (!fd.exists() || !fd.isDirectory()) { return new String[0]; }/* w w w . j a va2 s .co m*/ String rPattern = createRegexFromGlob(filePattern); return fd.list(new FilenameFilter() { @Override public boolean accept(File d, String fileName) { return Pattern.matches(rPattern, fileName); } }); } public static String createRegexFromGlob(String glob) { String out = "^"; for (int i = 0; i < glob.length(); ++i) { final char c = glob.charAt(i); switch (c) { case '*': out += ".*"; break; case '?': out += '.'; break; case '.': out += "\\."; break; case '\\': out += "\\\\"; break; default: out += c; } } out += '$'; return out; } }