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.
The extension check is case-sensitive by .
See FilenameUtils#wildcardMatchOnSystem for more information.
For example:
File dir = new File(".");
FileFilter fileFilter = new WildcardFileFilter("*test*.java~*~");
File[] files = dir.listFiles(fileFilter);
for (int i = 0; i < files.length; i++) {
System.out.println(files[i]);
}
| Modifier and Type | Field and Description |
|---|---|
| private IOCase | caseSensitivity
Whether the comparison is case sensitive. |
| private String[] | wildcards
The wildcards that will be used to match filenames. |
| Access | Constructor and Description |
|---|---|
| public | WildcardFileFilter(String
the wildcard to match wildcard)Construct a new case-sensitive wildcard filter for a single wildcard. |
| public | WildcardFileFilter(String
the wildcard to match, not null wildcard, IOCase how to handle case sensitivity, null means case-sensitive caseSensitivity)Construct a new wildcard filter for a single wildcard specifying case-sensitivity. |
| public | WildcardFileFilter(String[]
the array of wildcards to match wildcards)Construct a new case-sensitive wildcard filter for an array of wildcards. |
| public | WildcardFileFilter(String[]
the array of wildcards to match, not null wildcards, IOCase how to handle case sensitivity, null means case-sensitive caseSensitivity)Construct a new wildcard filter for an array of wildcards specifying case-sensitivity. |
| public | WildcardFileFilter(List<E>
the list of wildcards to match, not null wildcards)Construct a new case-sensitive wildcard filter for a list of wildcards. |
| public | WildcardFileFilter(List<E>
the list of wildcards to match, not null wildcards, IOCase how to handle case sensitivity, null means case-sensitive caseSensitivity)Construct a new wildcard filter for a list of wildcards specifying case-sensitivity. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the filename matches one of the wildcardsthe file directory dir, String the filename name)Overrides org. Implements org. |
| public boolean | Returns: true if the filename matches one of the wildcardsthe file to check file)Overrides org. Implements org. |
| caseSensitivity | back to summary |
|---|---|
| private IOCase caseSensitivity Whether the comparison is case sensitive. | |
| wildcards | back to summary |
|---|---|
| private String[] wildcards The wildcards that will be used to match filenames. | |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(String wildcard) Construct a new case-sensitive wildcard filter for a single wildcard.
| |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(String wildcard, IOCase caseSensitivity) Construct a new wildcard filter for a single wildcard specifying case-sensitivity.
| |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(String[] wildcards) 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.
| |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(String[] wildcards, IOCase caseSensitivity) Construct a new wildcard filter for an array of wildcards specifying case-sensitivity. The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.
| |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(List<E> wildcards) Construct a new case-sensitive wildcard filter for a list of wildcards.
| |
| WildcardFileFilter | back to summary |
|---|---|
| public WildcardFileFilter(List<E> wildcards, IOCase caseSensitivity) Construct a new wildcard filter for a list of wildcards specifying case-sensitivity.
| |
| accept | back to summary |
|---|---|
| public boolean accept(File dir, String name) Overrides org. Implements org. Checks to see if the filename matches one of the wildcards. | |
| accept | back to summary |
|---|---|
| public boolean accept(File file) Overrides org. Implements org. Checks to see if the filename matches one of the wildcards.
| |