public class RegexFileFilter extends AbstractFileFilter implements java.io.Serializable
See java.util.regex.Pattern for regex matching rules.
e.g.
File dir = FileUtils.current();
FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
File[] files = dir.listFiles(fileFilter);
for (String file : files) {
System.out.println(file);
}
final Path dir = PathUtils.current();
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());
Serialization is deprecated and will be removed in 3.0.
EMPTY_STRING_ARRAY| Constructor and Description |
|---|
RegexFileFilter(java.util.regex.Pattern pattern)
Constructs a new regular expression filter for a compiled regular expression
|
RegexFileFilter(java.util.regex.Pattern pattern,
java.util.function.Function<java.nio.file.Path,java.lang.String> pathToString)
Constructs a new regular expression filter for a compiled regular expression
|
RegexFileFilter(java.lang.String pattern)
Constructs a new regular expression filter.
|
RegexFileFilter(java.lang.String pattern,
int flags)
Constructs a new regular expression filter with the specified flags.
|
RegexFileFilter(java.lang.String pattern,
IOCase ioCase)
Constructs a new regular expression filter with the specified flags case sensitivity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(java.io.File dir,
java.lang.String name)
Checks to see if the file name matches one of the regular expressions.
|
java.nio.file.FileVisitResult |
accept(java.nio.file.Path path,
java.nio.file.attribute.BasicFileAttributes attributes)
Checks to see if the file name matches one of the regular expressions.
|
java.lang.String |
toString()
Returns a debug string.
|
accept, postVisitDirectory, preVisitDirectory, visitFile, visitFileFailedequals, getClass, hashCode, notify, notifyAll, wait, wait, waitand, negate, orpublic RegexFileFilter(java.util.regex.Pattern pattern)
pattern - regular expression to match.java.lang.NullPointerException - if the pattern is null.public RegexFileFilter(java.util.regex.Pattern pattern,
java.util.function.Function<java.nio.file.Path,java.lang.String> pathToString)
pattern - regular expression to match.pathToString - How convert a path to a string.java.lang.NullPointerException - if the pattern is null.public RegexFileFilter(java.lang.String pattern)
pattern - regular string expression to matchjava.lang.NullPointerException - if the pattern is nullpublic RegexFileFilter(java.lang.String pattern,
int flags)
pattern - regular string expression to matchflags - pattern flags - e.g. Pattern.CASE_INSENSITIVEjava.lang.IllegalArgumentException - if the pattern is nullpublic RegexFileFilter(java.lang.String pattern,
IOCase ioCase)
pattern - regular string expression to matchioCase - how to handle case sensitivity, null means case-sensitivejava.lang.IllegalArgumentException - if the pattern is nullpublic boolean accept(java.io.File dir,
java.lang.String name)
accept in interface java.io.FilenameFilteraccept in interface IOFileFilteraccept in class AbstractFileFilterdir - the file directory (ignored)name - the file namepublic java.nio.file.FileVisitResult accept(java.nio.file.Path path,
java.nio.file.attribute.BasicFileAttributes attributes)
accept in interface PathFilteraccept in interface IOFileFilterpath - the pathattributes - the path attributespublic java.lang.String toString()
toString in class AbstractFileFilterCopyright © 2010 - 2023 Adobe. All Rights Reserved