public class WildcardFileFilter extends Object implements FileFilter, Serializable
This filter selects files and directories based on one or more wildcards. Testing is case-sensitive by default, but this can be configured.
The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters. This is the same as often found on Dos/Unix command lines.
For example, to retrieve and print all java files that have the expression test in the name in the current directory:
FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files; files = dir.findFiles(new FileFilterSelector(new WildcardFileFilter("*test*.java"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }
Constructor and Description |
---|
WildcardFileFilter(IOCase caseSensitivity,
List<String> wildcards)
Construct a new wildcard filter for a list of wildcards specifying
case-sensitivity.
|
WildcardFileFilter(IOCase caseSensitivity,
String... wildcards)
Construct a new wildcard filter for an array of wildcards specifying
case-sensitivity.
|
WildcardFileFilter(List<String> wildcards)
Construct a new case-sensitive wildcard filter for a list of wildcards.
|
WildcardFileFilter(String... wildcards)
Construct a new case-sensitive wildcard filter for an array of wildcards.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(FileSelectInfo fileSelectInfo)
Checks to see if the file name matches one of the wildcards.
|
String |
toString()
Provide a String representation of this file filter.
|
public WildcardFileFilter(List<String> wildcards)
wildcards
- the list of wildcards to match, not nullpublic WildcardFileFilter(IOCase caseSensitivity, List<String> wildcards)
caseSensitivity
- how to handle case sensitivity, null means
case-sensitivewildcards
- the list of wildcards to match, not nullpublic WildcardFileFilter(String... wildcards)
The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.
wildcards
- the array of wildcards to matchpublic WildcardFileFilter(IOCase caseSensitivity, String... wildcards)
caseSensitivity
- how to handle case sensitivity, null means
case-sensitivewildcards
- the array of wildcards to match, not nullpublic boolean accept(FileSelectInfo fileSelectInfo)
accept
in interface FileFilter
fileSelectInfo
- the file to checkCopyright © 2002–2020 The Apache Software Foundation. All rights reserved.