org.apache.commons.io.filefilter
Class AgeFileFilter

java.lang.Object
  extended byorg.apache.commons.io.filefilter.AbstractFileFilter
      extended byorg.apache.commons.io.filefilter.AgeFileFilter
All Implemented Interfaces:
FileFilter, FilenameFilter, IOFileFilter

public class AgeFileFilter
extends AbstractFileFilter

Filters files based on a cutoff time, can filter either older or newer files.

For example, to print all files and directories in the current directory older than one day:

 File dir = new File(".");
 // We are interested in files older than one day
 long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
 String[] files = dir.list( new AgeFileFilter(cutoff) );
 for ( int i = 0; i < files.length; i++ ) {
     System.out.println(files[i]);
 }
 

Since:
Commons IO 1.2
Version:
$Id: AgeFileFilter.java 369075 2006-01-14 18:23:42Z scolebourne $

Constructor Summary
AgeFileFilter(Date cutoffDate)
          Constructs a new age file filter for files older than a certain cutoff date.
AgeFileFilter(Date cutoffDate, boolean acceptOlder)
          Constructs a new age file filter for files on any one side of a certain cutoff date.
AgeFileFilter(File cutoffReference)
          Constructs a new age file filter for files older than a certain File (whose last modification time will be used as reference).
AgeFileFilter(File cutoffReference, boolean acceptOlder)
          Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).
AgeFileFilter(long cutoff)
          Constructs a new age file filter for files older than a certain cutoff.
AgeFileFilter(long cutoff, boolean acceptOlder)
          Constructs a new age file filter for files on any one side of a certain cutoff.
 
Method Summary
 boolean accept(File file)
          Checks to see if the last modification of the file matches cutoff favorably.
 
Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter
accept
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgeFileFilter

public AgeFileFilter(long cutoff)
Constructs a new age file filter for files older than a certain cutoff.

Parameters:
cutoff - the threshold age of the files

AgeFileFilter

public AgeFileFilter(long cutoff,
                     boolean acceptOlder)
Constructs a new age file filter for files on any one side of a certain cutoff.

Parameters:
cutoff - the threshold age of the files
acceptOlder - if true, older files are accepted, else newer ones

AgeFileFilter

public AgeFileFilter(Date cutoffDate)
Constructs a new age file filter for files older than a certain cutoff date.

Parameters:
cutoffDate - the threshold age of the files

AgeFileFilter

public AgeFileFilter(Date cutoffDate,
                     boolean acceptOlder)
Constructs a new age file filter for files on any one side of a certain cutoff date.

Parameters:
cutoffDate - the threshold age of the files
acceptOlder - if true, older files are accepted, else newer ones

AgeFileFilter

public AgeFileFilter(File cutoffReference)
Constructs a new age file filter for files older than a certain File (whose last modification time will be used as reference).

Parameters:
cutoffReference - the file whose last modification time is usesd as the threshold age of the files

AgeFileFilter

public AgeFileFilter(File cutoffReference,
                     boolean acceptOlder)
Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).

Parameters:
cutoffReference - the file whose last modification time is usesd as the threshold age of the files
acceptOlder - if true, older files are accepted, else newer ones
Method Detail

accept

public boolean accept(File file)
Checks to see if the last modification of the file matches cutoff favorably. If last modification time equals cutoff, file is not selected.

Specified by:
accept in interface IOFileFilter
Overrides:
accept in class AbstractFileFilter
Parameters:
file - the File to check
Returns:
true if the filename matches


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