Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.io.filefilter
Class RegexFileFilter

    java.lang.Object
      org.apache.commons.io.filefilter.AbstractFileFilter
          org.apache.commons.io.filefilter.RegexFileFilter

All Implemented Interfaces:
  FileFilter, FilenameFilter, Serializable, IOFileFilter

    public class RegexFileFilter

extends AbstractFileFilter
implements Serializable

Filters files using supplied regular expression(s).

See java.util.regex.Pattern for regex matching rules

e.g.

     File dir = new File(".");
     FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
     File[] files = dir.listFiles(fileFilter);
     for (int i = 0; i < files.length; i++) {
       System.out.println(files[i]);
     }

Since:
  Commons IO 1.4
Version:
  $Revision: 606381 $
Author:
  Oliver Siegmar
See Also:
  Serialized Form

Constructor Summary
`RegexFileFilter(Pattern pattern)` Construct a new regular expression filter for a compiled regular expression
`RegexFileFilter(String pattern)` Construct a new regular expression filter.
`RegexFileFilter(String pattern, int flags)` Construct a new regular expression filter with the specified flags.
`RegexFileFilter(String pattern, IOCase caseSensitivity)` Construct a new regular expression filter with the specified flags case sensitivity.

Method Summary
`boolean` | `accept(File dir, String name)` Checks to see if the filename matches one of the regular expressions.

Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter
`accept, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### RegexFileFilter

    public RegexFileFilter(String pattern)

  Construct a new regular expression filter.

  Parameters:
    `pattern` - regular string expression to match
  Throws:
    `IllegalArgumentException` - if the pattern is null

### RegexFileFilter

    public RegexFileFilter(String pattern,
                           IOCase caseSensitivity)

  Construct a new regular expression filter with the specified flags case sensitivity.

  Parameters:
    `pattern` - regular string expression to match
    `caseSensitivity` - how to handle case sensitivity, null means case-sensitive
  Throws:
    `IllegalArgumentException` - if the pattern is null

### RegexFileFilter

    public RegexFileFilter(String pattern,
                           int flags)

  Construct a new regular expression filter with the specified flags.

  Parameters:
    `pattern` - regular string expression to match
    `flags` - pattern flags - e.g. `Pattern.CASE_INSENSITIVE`
  Throws:
    `IllegalArgumentException` - if the pattern is null

### RegexFileFilter

    public RegexFileFilter(Pattern pattern)

  Construct a new regular expression filter for a compiled regular expression

  Parameters:
    `pattern` - regular expression to match
  Throws:
    `IllegalArgumentException` - if the pattern is null

Method Detail

### accept

    public boolean accept(File dir,
                          String name)

  Checks to see if the filename matches one of the regular expressions.

  Specified by:
    `accept` in interface `FilenameFilter`
  Specified by:
    `accept` in interface `IOFileFilter`
  Overrides:
    `accept` in class `AbstractFileFilter`
  Parameters:
    `dir` - the file directory
    `name` - the filename
  Returns:
    true if the filename matches one of the regular expressions

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.