public class RegexFileFilter extends AbstractFileFilter implements Serializable
See java.util.regex.Pattern for regex matching rules.
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);
}
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());
EMPTY_STRING_ARRAY| Constructor and Description |
|---|
RegexFileFilter(Pattern pattern)
Constructs a new regular expression filter for a compiled regular expression
|
RegexFileFilter(Pattern pattern,
Function<Path,String> pathToString)
Constructs a new regular expression filter for a compiled regular expression
|
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.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(File dir,
String name)
Checks to see if the file name matches one of the regular expressions.
|
FileVisitResult |
accept(Path path,
BasicFileAttributes attributes)
Checks to see if the file name matches one of the regular expressions.
|
String |
toString()
Returns a debug string.
|
accept, handle, postVisitDirectory, preVisitDirectory, visitFile, visitFileFailedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitand, negate, orpublic RegexFileFilter(Pattern pattern)
pattern - regular expression to match.IllegalArgumentException - if the pattern is null.public RegexFileFilter(Pattern pattern, Function<Path,String> pathToString)
pattern - regular expression to match.pathToString - How convert a path to a string.IllegalArgumentException - if the pattern is null.public RegexFileFilter(String pattern)
pattern - regular string expression to matchIllegalArgumentException - if the pattern is nullpublic RegexFileFilter(String pattern, int flags)
pattern - regular string expression to matchflags - pattern flags - e.g. Pattern.CASE_INSENSITIVEIllegalArgumentException - if the pattern is nullpublic RegexFileFilter(String pattern, IOCase caseSensitivity)
pattern - regular string expression to matchcaseSensitivity - how to handle case sensitivity, null means case-sensitiveIllegalArgumentException - if the pattern is nullpublic boolean accept(File dir, String name)
accept in interface FilenameFilteraccept in interface IOFileFilteraccept in class AbstractFileFilterdir - the file directory (ignored)name - the file namepublic FileVisitResult accept(Path path, BasicFileAttributes attributes)
accept in interface PathFilteraccept in interface IOFileFilterpath - the pathattributes - the path attributespublic String toString()
toString in class AbstractFileFilterCopyright © 2002–2021 The Apache Software Foundation. All rights reserved.