? RegexFileFilter
java.lang.Object
org.apache.commons.io.filefilter.AbstractFileFilter
org.apache.commons.io.filefilter.RegexFileFilter
- ????????:
FileFilter
,FilenameFilter
,Serializable
,FileVisitor<Path>
,PathFilter
,PathVisitor
,IOFileFilter
Filters files using supplied regular expression(s).
See java.util.regex.Pattern for regex matching rules.
Using Classic IO
e.g.
File dir = new File("."); FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$"); File[] files = dir.listFiles(fileFilter); for (String file : files) { System.out.println(file); }
Using NIO
final Path dir = Paths.get(""); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$")); // // Walk one dir Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk dir tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
- ???????:
- 1.4
- ????:
-
????
???????? org.apache.commons.io.filefilter.IOFileFilter
EMPTY_STRING_ARRAY
-
?????
????????RegexFileFilter
(String pattern) Constructs a new regular expression filter.RegexFileFilter
(String pattern, int flags) Constructs a new regular expression filter with the specified flags.RegexFileFilter
(String pattern, IOCase caseSensitivity) Constructs a new regular expression filter with the specified flags case sensitivity.RegexFileFilter
(Pattern pattern) Constructs a new regular expression filter for a compiled regular expressionRegexFileFilter
(Pattern pattern, Function<Path, String> pathToString) Constructs a new regular expression filter for a compiled regular expression -
????
??????????boolean
Checks to see if the file name matches one of the regular expressions.accept
(Path path, BasicFileAttributes attributes) Checks to see if the file name matches one of the regular expressions.toString()
Returns a debug string.??????? org.apache.commons.io.filefilter.AbstractFileFilter
accept, handle, postVisitDirectory, preVisitDirectory, visitFile, visitFileFailed
??????? java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
???????? org.apache.commons.io.filefilter.IOFileFilter
and, negate, or
-
???????
-
RegexFileFilter
Constructs a new regular expression filter for a compiled regular expression- ??:
pattern
- regular expression to match.- ??:
IllegalArgumentException
- if the pattern is null.
-
RegexFileFilter
Constructs a new regular expression filter for a compiled regular expression- ??:
pattern
- regular expression to match.pathToString
- How convert a path to a string.- ??:
IllegalArgumentException
- if the pattern is null.- ???????:
- 2.10.0
-
RegexFileFilter
Constructs a new regular expression filter.- ??:
pattern
- regular string expression to match- ??:
IllegalArgumentException
- if the pattern is null
-
RegexFileFilter
Constructs a new regular expression filter with the specified flags.- ??:
pattern
- regular string expression to matchflags
- pattern flags - e.g.Pattern.CASE_INSENSITIVE
- ??:
IllegalArgumentException
- if the pattern is null
-
RegexFileFilter
Constructs a new regular expression filter with the specified flags case sensitivity.- ??:
pattern
- regular string expression to matchcaseSensitivity
- how to handle case sensitivity, null means case-sensitive- ??:
IllegalArgumentException
- if the pattern is null
-
-
??????
-
accept
Checks to see if the file name matches one of the regular expressions.- ???:
accept
????FilenameFilter
- ???:
accept
????IOFileFilter
- ??:
accept
???AbstractFileFilter
- ??:
dir
- the file directory (ignored)name
- the file name- ??:
- true if the file name matches one of the regular expressions
-
accept
Checks to see if the file name matches one of the regular expressions.- ???:
accept
????IOFileFilter
- ???:
accept
????PathFilter
- ??:
path
- the pathattributes
- the path attributes- ??:
- true if the file name matches one of the regular expressions
-
toString
Returns a debug string.- ??:
toString
???AbstractFileFilter
- ??:
- a String representation
- ???????:
- 2.10.0
-