in reply to Quickest way to get the oldest file
A quick and dirty test for the oldest file in a directory follows. It currently makes no check to see if it's pointing to a regular file or something else (socket, directory, etc.). It just prints the name of the oldest file and the number of days since it was modified. I tested it a little and it seems to work.
use strict; use warnings; my $max = 0; my ( $time, $oldest ); opendir ( my $d, '.' ) || die "Can't get file list: $!\n"; my @file = readdir ( $d ); closedir ( $d ); foreach ( @file ) { next if /^\.{1,2}$/; $time = -M $_; if ( $time > $max ) { $max = $time; $oldest = $_; } } print "$oldest was modified $max days ago\n";
|
|---|