Line | |
---|
1 | package org.apollo.util;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FilenameFilter;
|
---|
5 | import java.util.regex.Pattern;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * A FileFilter that filters via regular expressions.
|
---|
9 | * @author Bruce Eckel
|
---|
10 | */
|
---|
11 | public class RegExpFileFilter implements FilenameFilter {
|
---|
12 | private Pattern pattern;
|
---|
13 |
|
---|
14 | public RegExpFileFilter(String regex) {
|
---|
15 | pattern = Pattern.compile(regex);
|
---|
16 | }
|
---|
17 |
|
---|
18 | public boolean accept(File dir, String name) {
|
---|
19 | // Strip path information, search for regex:
|
---|
20 | return pattern.matcher(new File(name).getName()).matches();
|
---|
21 | }
|
---|
22 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.