Top Description Fields Constructors Methods
org.apache.commons.io.filefilter

public Class WildcardFileFilter

extends AbstractFileFilter
Class Inheritance
Imports
java.io.File, java.util.List, org.apache.commons.io.FilenameUtils, .IOCase

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. 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]);
}
Author
Jason Anderson
Since
Commons IO 1.3
Version
$Revision: 155419 $ $Date: 2006-08-28 13:57:00 +0200 (Mo, 28 Aug 2006) $

Field Summary

Modifier and TypeField and Description
private IOCase
caseSensitivity

Whether the comparison is case sensitive.

private String[]
wildcards

The wildcards that will be used to match filenames.

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the filename matches one of the wildcards
accept
(File
the file directory
dir
,
String
the filename
name
)

Overrides org.apache.commons.io.filefilter.AbstractFileFilter.accept.

Implements org.apache.commons.io.filefilter.IOFileFilter.accept.

Checks to see if the filename matches one of the wildcards.
public boolean

Returns:

true if the filename matches one of the wildcards
accept
(File
the file to check
file
)

Overrides org.apache.commons.io.filefilter.AbstractFileFilter.accept.

Implements org.apache.commons.io.filefilter.IOFileFilter.accept.

Checks to see if the filename matches one of the wildcards.

Field Detail

caseSensitivityback to summary
private IOCase caseSensitivity

Whether the comparison is case sensitive.

wildcardsback to summary
private String[] wildcards

The wildcards that will be used to match filenames.

Constructor Detail

WildcardFileFilterback to summary
public WildcardFileFilter(String wildcard)

Construct a new case-sensitive wildcard filter for a single wildcard.

Parameters
wildcard:String

the wildcard to match

Exceptions
IllegalArgumentException:
if the pattern is null
WildcardFileFilterback to summary
public WildcardFileFilter(String wildcard, IOCase caseSensitivity)

Construct a new wildcard filter for a single wildcard specifying case-sensitivity.

Parameters
wildcard:String

the wildcard to match, not null

caseSensitivity:IOCase

how to handle case sensitivity, null means case-sensitive

Exceptions
IllegalArgumentException:
if the pattern is null
WildcardFileFilterback 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.

Parameters
wildcards:String[]

the array of wildcards to match

Exceptions
IllegalArgumentException:
if the pattern array is null
WildcardFileFilterback 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.

Parameters
wildcards:String[]

the array of wildcards to match, not null

caseSensitivity:IOCase

how to handle case sensitivity, null means case-sensitive

Exceptions
IllegalArgumentException:
if the pattern array is null
WildcardFileFilterback to summary
public WildcardFileFilter(List<E> wildcards)

Construct a new case-sensitive wildcard filter for a list of wildcards.

Parameters
wildcards:List<E>

the list of wildcards to match, not null

Exceptions
IllegalArgumentException:
if the pattern list is null
ClassCastException:
if the list does not contain Strings
WildcardFileFilterback to summary
public WildcardFileFilter(List<E> wildcards, IOCase caseSensitivity)

Construct a new wildcard filter for a list of wildcards specifying case-sensitivity.

Parameters
wildcards:List<E>

the list of wildcards to match, not null

caseSensitivity:IOCase

how to handle case sensitivity, null means case-sensitive

Exceptions
IllegalArgumentException:
if the pattern list is null
ClassCastException:
if the list does not contain Strings

Method Detail

acceptback to summary
public boolean accept(File dir, String name)

Overrides org.apache.commons.io.filefilter.AbstractFileFilter.accept.

Implements org.apache.commons.io.filefilter.IOFileFilter.accept.

Checks to see if the filename matches one of the wildcards.

Parameters
dir:File

the file directory

name:String

the filename

Returns:boolean

true if the filename matches one of the wildcards

acceptback to summary
public boolean accept(File file)

Overrides org.apache.commons.io.filefilter.AbstractFileFilter.accept.

Implements org.apache.commons.io.filefilter.IOFileFilter.accept.

Checks to see if the filename matches one of the wildcards.

Parameters
file:File

the file to check

Returns:boolean

true if the filename matches one of the wildcards