Package org.apache.commons.io.filefilter
Class AgeFileFilter
java.lang.Object
org.apache.commons.io.filefilter.AbstractFileFilter
org.apache.commons.io.filefilter.AgeFileFilter
- All Implemented Interfaces:
- FileFilter,- FilenameFilter,- Serializable,- FileVisitor<Path>,- PathMatcher,- PathFilter,- PathVisitor,- IOFileFilter
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:
Using Classic IO
 Path dir = PathUtils.current();
 // We are interested in files older than one day
 Instant cutoff = Instant.now().minus(Duration.ofDays(1));
 String[] files = dir.list(new AgeFileFilter(cutoff));
 for (String file : files) {
     System.out.println(file);
 }
 
 Using NIO
Path dir = PathUtils.current(); // We are interested in files older than one day Instant cutoff = Instant.now().minus(Duration.ofDays(1)); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one directoryectory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
Deprecating Serialization
Serialization is deprecated and will be removed in 3.0.
- Since:
- 1.2
- See Also:
- 
Field SummaryFields inherited from interface org.apache.commons.io.filefilter.IOFileFilterEMPTY_STRING_ARRAY
- 
Constructor SummaryConstructorsConstructorDescriptionAgeFileFilter(long cutoffMillis) Constructs a new age file filter for files equal to or older than a certain cutoffAgeFileFilter(long cutoffMillis, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff.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).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(Instant cutoffInstant) Constructs a new age file filter for files equal to or older than a certain cutoff.AgeFileFilter(Instant cutoffInstant, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff.AgeFileFilter(Date cutoffDate) Constructs a new age file filter for files older than (at or before) 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.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanTests to see if the last modification of the file matches cutoff favorably.accept(Path file, BasicFileAttributes attributes) Tests to see if the last modification of the file matches cutoff favorably.toString()Provide a String representation of this file filter.Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilteraccept, handle, postVisitDirectory, preVisitDirectory, visitFile, visitFileFailedMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.io.filefilter.IOFileFilterand, matches, negate, or
- 
Constructor Details- 
AgeFileFilterConstructs a new age file filter for files older than (at or before) a certain cutoff date.- Parameters:
- cutoffDate- the threshold age of the files
 
- 
AgeFileFilterConstructs 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 (at or before the cutoff) are accepted, else newer ones (after the cutoff).
 
- 
AgeFileFilterConstructs 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- the file whose last modification time is used as the threshold age of the files
 
- 
AgeFileFilterConstructs 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 used as the threshold age of the files
- acceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
 
- 
AgeFileFilterConstructs a new age file filter for files equal to or older than a certain cutoff.- Parameters:
- cutoffInstant- The cutoff time threshold since the epoch (00:00:00 GMT, January 1, 1970).
- Since:
- 2.12.0
 
- 
AgeFileFilterConstructs a new age file filter for files on any one side of a certain cutoff.- Parameters:
- cutoffInstant- The cutoff time threshold since the epoch (00:00:00 GMT, January 1, 1970).
- acceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
- Since:
- 2.12.0
 
- 
AgeFileFilterConstructs a new age file filter for files equal to or older than a certain cutoff- Parameters:
- cutoffMillis- The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
 
- 
AgeFileFilterConstructs a new age file filter for files on any one side of a certain cutoff.- Parameters:
- cutoffMillis- The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
- acceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
 
 
- 
- 
Method Details- 
acceptTests 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. - Specified by:
- acceptin interface- FileFilter
- Specified by:
- acceptin interface- IOFileFilter
- Overrides:
- acceptin class- AbstractFileFilter
- Parameters:
- file- the File to check
- Returns:
- true if the file name matches
 
- 
acceptTests 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. - Specified by:
- acceptin interface- IOFileFilter
- Specified by:
- acceptin interface- PathFilter
- Parameters:
- file- the File to check
- attributes- the path's basic attributes (may be null).
- Returns:
- true if the file name matches
- Since:
- 2.9.0
 
- 
toStringProvide a String representation of this file filter.- Overrides:
- toStringin class- AbstractFileFilter
- Returns:
- a String representation
 
 
-