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

public Class AgeFileFilter

extends AbstractFileFilter
Class Inheritance
Imports
java.io.File, java.util.Date, org.apache.commons.io.FileUtils

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

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]);
}
Author
Rahul Akolkar
Since
Commons IO 1.2
Version
$Id: AgeFileFilter.java 463570 2006-10-13 06:14:41Z niallp $

Field Summary

Modifier and TypeField and Description
private boolean
acceptOlder

Whether the files accepted will be older or newer.

private long
cutoff

The cutoff time threshold.

Constructor Summary

AccessConstructor and Description
public
AgeFileFilter(long
the threshold age of the files
cutoff
)

Constructs a new age file filter for files equal to or older than a certain cutoff

public
AgeFileFilter(long
the threshold age of the files
cutoff
,
boolean
if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
acceptOlder
)

Constructs a new age file filter for files on any one side of a certain cutoff.

public
AgeFileFilter(Date
the threshold age of the files
cutoffDate
)

Constructs a new age file filter for files older than (at or before) a certain cutoff date.

public
AgeFileFilter(Date
the threshold age of the files
cutoffDate
,
boolean
if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
acceptOlder
)

Constructs a new age file filter for files on any one side of a certain cutoff date.

public
AgeFileFilter(File
the file whose last modification time is usesd as the threshold age of the files
cutoffReference
)

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

public
AgeFileFilter(File
the file whose last modification time is usesd as the threshold age of the files
cutoffReference
,
boolean
if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
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).

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the filename matches
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 last modification of the file matches cutoff favorably.
Inherited from org.apache.commons.io.filefilter.AbstractFileFilter:
accept

Field Detail

acceptOlderback to summary
private boolean acceptOlder

Whether the files accepted will be older or newer.

cutoffback to summary
private long cutoff

The cutoff time threshold.

Constructor Detail

AgeFileFilterback to summary
public AgeFileFilter(long cutoff)

Constructs a new age file filter for files equal to or older than a certain cutoff

Parameters
cutoff:long

the threshold age of the files

AgeFileFilterback to summary
public AgeFileFilter(long cutoff, boolean acceptOlder)

Constructs a new age file filter for files on any one side of a certain cutoff.

Parameters
cutoff:long

the threshold age of the files

acceptOlder:boolean

if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).

AgeFileFilterback to summary
public AgeFileFilter(Date cutoffDate)

Constructs a new age file filter for files older than (at or before) a certain cutoff date.

Parameters
cutoffDate:Date

the threshold age of the files

AgeFileFilterback to summary
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:Date

the threshold age of the files

acceptOlder:boolean

if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).

AgeFileFilterback to summary
public AgeFileFilter(File cutoffReference)

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

Parameters
cutoffReference:File

the file whose last modification time is usesd as the threshold age of the files

AgeFileFilterback to summary
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:File

the file whose last modification time is usesd as the threshold age of the files

acceptOlder:boolean

if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).

Method Detail

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 last modification of the file matches cutoff favorably.

If last modification time equals cutoff and newer files are required, file IS NOT selected. If last modification time equals cutoff and older files are required, file IS selected.

Parameters
file:File

the File to check

Returns:boolean

true if the filename matches