org.apache.commons.io.filefilter

Class WildcardFilter

Implemented Interfaces:
FileFilter, FilenameFilter, IOFileFilter

public class WildcardFilter
extends AbstractFileFilter

Filters files using supplied wildcard(s).

See org.apache.commons.io.find.FilenameUtils.wildcardMatch() for wildcard matching rules

e.g.

 File dir = new File(".");
 FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
 File[] files = dir.listFiles(fileFilter);
 for (int i = 0; i <32files.length; i++) {
   System.out.println(files[i]);
 }
 
Version:
$Revision: 155419 $ $Date: 2005-02-26 08:02:41 -0500 (Sat, 26 Feb 2005) $
Author:
Jason Anderson
Since:
Commons IO 1.1

Field Summary

private String[]
wildcards
The wildcards that will be used to match filenames

Constructor Summary

WildcardFilter(List wildcards)
Construct a new wildcard filter for a list of wildcards
WildcardFilter(String wildcard)
Construct a new wildcard filter for a single wildcard
WildcardFilter(String[] wildcards)
Construct a new wildcard filter for an array of wildcards

Method Summary

boolean
accept(File file)
Checks to see if the filename matches one of the wildcards.
boolean
accept(File dir, String name)
Checks to see if the filename matches one of the wildcards.

Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter

accept, accept

Field Details

wildcards

private String[] wildcards
The wildcards that will be used to match filenames

Constructor Details

WildcardFilter

public WildcardFilter(List wildcards)
Construct a new wildcard filter for a list of wildcards
Parameters:
wildcards - list of wildcards to match

WildcardFilter

public WildcardFilter(String wildcard)
Construct a new wildcard filter for a single wildcard
Parameters:
wildcard - wildcard to match

WildcardFilter

public WildcardFilter(String[] wildcards)
Construct a new wildcard filter for an array of wildcards
Parameters:
wildcards - wildcards to match

Method Details

accept

public boolean accept(File file)
Checks to see if the filename matches one of the wildcards.
Specified by:
accept in interface IOFileFilter
Overrides:
accept in interface AbstractFileFilter
Parameters:
file - the file to check
Returns:
true if the filename matches one of the wildcards

accept

public boolean accept(File dir,
                      String name)
Checks to see if the filename matches one of the wildcards.
Specified by:
accept in interface IOFileFilter
Overrides:
accept in interface AbstractFileFilter
Parameters:
dir - the file directory
name - the filename
Returns:
true if the filename matches one of the wildcards