Well, you didn't say a platform, but if you're on Unix, no matter how you look at the date you're out of luck, because Unix doesn't maintain the "creation time" of files, regardless of some of the docs that erroneously say so. The ctime value is the "last inode change time", not creation time.
-- Randal L. Schwartz, Perl hacker | [reply] |
As merlyn notes, you can't get a files' creation date on Unix (and possibly other platforms), but often using a file's last modification date instead will work in many cases.
If that's an acceptable alternative, then you can do something like...
use POSIX qw/ strftime /;
sub mdate {
my($file,$format) = @_;
# Unless otherwise specified, use
# MM/DD/YYYY as date format.
$format ||= '%m/%d/%Y';
my $date = ( stat($file) )[9];
return strftime( $format => localtime $date );
}
my $dir = '/path/to/files';
my $date = '04/11/2002';
chdir $dir or die "Cannot chdir($dir): $!\n";
opendir DIR, '.' or die "Cannot opendir($dir): $!\n";
foreach my $file ( readdir DIR ) {
print $file, "\n" if mdate($file) eq $date;
}
--k.
| [reply] [d/l] |
You need to figure out (probably using Date::Parse or the like) the epoch seconds for 0000 to 2359 on that date, then look for files where stat returns a value between
them.
| [reply] |