public class AgeFileFilter extends AbstractFileFilter implements java.io.Serializable
For example, to print all files and directories in the current directory older than one day:
Path dir = Paths.get(""); // 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 (String file : files) { System.out.println(file); }
Path dir = Paths.get(""); // We are interested in files older than one day long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one dir Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk dir tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
Modifier and Type | Field and Description |
---|---|
private boolean |
acceptOlder
Whether the files accepted will be older or newer.
|
private long |
cutoffMillis
The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
|
private static long |
serialVersionUID |
EMPTY_STRING_ARRAY
Constructor and Description |
---|
AgeFileFilter(java.util.Date cutoffDate)
Constructs a new age file filter for files older than (at or before) a certain cutoff date.
|
AgeFileFilter(java.util.Date cutoffDate,
boolean acceptOlder)
Constructs a new age file filter for files on any one side of a certain cutoff date.
|
AgeFileFilter(java.io.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(java.io.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 cutoffMillis)
Constructs a new age file filter for files equal to or older than a certain cutoff
|
AgeFileFilter(long cutoffMillis,
boolean acceptOlder)
Constructs a new age file filter for files on any one side of a certain cutoff.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file)
Checks to see if the last modification of the file matches cutoff favorably.
|
java.nio.file.FileVisitResult |
accept(java.nio.file.Path file,
java.nio.file.attribute.BasicFileAttributes attributes)
Checks to see if the last modification of the file matches cutoff favorably.
|
java.lang.String |
toString()
Provide a String representation of this file filter.
|
accept, handle, postVisitDirectory, preVisitDirectory, toFileVisitResult, visitFile, visitFileFailed
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
and, negate, or
private static final long serialVersionUID
private final boolean acceptOlder
private final long cutoffMillis
public AgeFileFilter(java.util.Date cutoffDate)
cutoffDate
- the threshold age of the filespublic AgeFileFilter(java.util.Date cutoffDate, boolean acceptOlder)
cutoffDate
- the threshold age of the filesacceptOlder
- if true, older files (at or before the cutoff) are accepted, else newer ones (after the
cutoff).public AgeFileFilter(java.io.File cutoffReference)
cutoffReference
- the file whose last modification time is used as the threshold age of the filespublic AgeFileFilter(java.io.File cutoffReference, boolean acceptOlder)
cutoffReference
- the file whose last modification time is used as the threshold age of the filesacceptOlder
- if true, older files (at or before the cutoff) are accepted, else newer ones (after the
cutoff).public AgeFileFilter(long cutoffMillis)
cutoffMillis
- The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1,
1970).public AgeFileFilter(long cutoffMillis, boolean acceptOlder)
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).public boolean accept(java.io.File file)
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.
accept
in interface java.io.FileFilter
accept
in interface IOFileFilter
accept
in class AbstractFileFilter
file
- the File to checkpublic java.nio.file.FileVisitResult accept(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attributes)
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.
accept
in interface PathFilter
accept
in interface IOFileFilter
file
- the File to checkattributes
- the file's basic attributes (TODO may be null).public java.lang.String toString()
toString
in class AbstractFileFilter