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

public Class WildcardFilter

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

Deprecated

Use WilcardFileFilter. Deprecated as this class performs directory filtering which it shouldn't do, but that can't be removed due to compatability.

Filters files using the supplied wildcards.

This filter selects files, but not directories, based on one or more wildcards and using case-sensitive comparison.

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. See FilenameUtils#wildcardMatch for more information.

For example:

File dir = new File(".");
FileFilter fileFilter = new WildcardFilter("*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.1
Version
$Revision: 437680 $ $Date: 2006-08-28 13:57:00 +0200 (Mo, 28 Aug 2006) $

Field Summary

Modifier and TypeField and Description
private String[]
wildcards

The wildcards that will be used to match filenames.

Constructor Summary

AccessConstructor and Description
public
WildcardFilter(String
the wildcard to match
wildcard
)

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

public
WildcardFilter(String[]
the array of wildcards to match
wildcards
)

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

public
WildcardFilter(List<E>
the list of wildcards to match
wildcards
)

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

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

wildcardsback to summary
private String[] wildcards

The wildcards that will be used to match filenames.

Constructor Detail

WildcardFilterback to summary
public WildcardFilter(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
WildcardFilterback to summary
public WildcardFilter(String[] wildcards)

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

Parameters
wildcards:String[]

the array of wildcards to match

Exceptions
IllegalArgumentException:
if the pattern array is null
WildcardFilterback to summary
public WildcardFilter(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

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