Here you can find the source of getFileListByRegex(String dir, final String regex)
Parameter | Description |
---|---|
dir | the given directory |
regex | the given regulate expression. |
public static String[] getFileListByRegex(String dir, final String regex)
//package com.java2s; import java.io.File; import java.io.FilenameFilter; public class Main { /**/*from w ww. ja v a2 s. c o m*/ * Get the File list under the given directory by the regex. If the * parameter dir is not a directory, return null. * * @param dir * the given directory * @param regex * the given regulate expression. * @return */ public static String[] getFileListByRegex(String dir, final String regex) { File file = new File(dir); if (!file.isDirectory()) { return null; } FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.matches(regex); } }; return file.list(filter); } public static boolean isDirectory(String path) { File file = new File(path); return file.isDirectory(); } }