Class WildcardFileFilter
java.lang.Object
org.apache.commons.vfs2.filter.WildcardFileFilter
- All Implemented Interfaces:
Serializable, FileFilter
Filters files using the supplied wildcards.
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]);
}
- Since:
- 2.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IOCaseWhether the comparison is case sensitive.private static final longThe wildcards that will be used to match file names. -
Constructor Summary
ConstructorsConstructorDescriptionWildcardFileFilter(String... wildcards) Construct a new case-sensitive wildcard filter for an array of wildcards.WildcardFileFilter(List<String> wildcards) Construct a new case-sensitive wildcard filter for a list of wildcards.WildcardFileFilter(IOCase caseSensitivity, String... wildcards) Construct a new wildcard filter for an array of wildcards specifying case-sensitivity.WildcardFileFilter(IOCase caseSensitivity, List<String> wildcards) Construct a new wildcard filter for a list of wildcards specifying case-sensitivity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(FileSelectInfo fileSelectInfo) Checks to see if the file name matches one of the wildcards.(package private) static String[]splitOnTokens(String text) Splits a string into a number of tokens.toString()Provide a String representation of this file filter.(package private) static booleanwildcardMatch(String fileName, String wildcardMatcher, IOCase caseSensitivity) Checks a file name to see if it matches the specified wildcard matcher allowing control over case-sensitivity.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
caseSensitivity
Whether the comparison is case sensitive. -
wildcards
-
-
Constructor Details
-
WildcardFileFilter
-
WildcardFileFilter
-
WildcardFileFilter
Construct a new case-sensitive wildcard filter for an array of wildcards.The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.
- Parameters:
wildcards- the array of wildcards to match
-
WildcardFileFilter
-
-
Method Details
-
accept
Checks to see if the file name matches one of the wildcards.- Specified by:
acceptin interfaceFileFilter- Parameters:
fileSelectInfo- the file to check- Returns:
- true if the file name matches one of the wildcards
-
toString
-
splitOnTokens
-
wildcardMatch
Checks a file name to see if it matches the specified wildcard matcher allowing control over case-sensitivity.The wildcard matcher uses the characters '?' and '*' to represent a single or multiple (zero or more) wildcard characters. N.B. the sequence "*?" does not work properly at present in match strings.
- Parameters:
fileName- the file name to match onwildcardMatcher- the wildcard string to match againstcaseSensitivity- what case sensitivity rule to use, null means case-sensitive- Returns:
- true if the file name matches the wilcard string
-