org.apache.commons.io.filefilter
public class RegexFileFilter extends AbstractFileFilter implements Serializable
File dir = new File("."); FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$"); File[] files = dir.listFiles(fileFilter); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }
Since: Commons IO 1.4
Version: $Revision: 606381 $
Field Summary | |
---|---|
Pattern | pattern The regular expression pattern that will be used to match filenames |
Constructor Summary | |
---|---|
RegexFileFilter(String pattern)
Construct a new regular expression filter.
| |
RegexFileFilter(String pattern, IOCase caseSensitivity)
Construct a new regular expression filter with the specified flags case sensitivity.
| |
RegexFileFilter(String pattern, int flags)
Construct a new regular expression filter with the specified flags.
| |
RegexFileFilter(Pattern pattern)
Construct a new regular expression filter for a compiled regular expression
|
Method Summary | |
---|---|
boolean | accept(File dir, String name)
Checks to see if the filename matches one of the regular expressions.
|
Parameters: pattern regular string expression to match
Throws: IllegalArgumentException if the pattern is null
Parameters: pattern regular string expression to match caseSensitivity how to handle case sensitivity, null means case-sensitive
Throws: IllegalArgumentException if the pattern is null
Parameters: pattern regular string expression to match flags pattern flags - e.g. Pattern#CASE_INSENSITIVE
Throws: IllegalArgumentException if the pattern is null
Parameters: pattern regular expression to match
Throws: IllegalArgumentException if the pattern is null
Parameters: dir the file directory name the filename
Returns: true if the filename matches one of the regular expressions