rauschy33 has asked for the wisdom of the Perl Monks concerning the following question:

I need a little more help. I have been struggling to find the file date of the file itself. I know that stat will return the last access time of the file, but I don't know how to read that number and I just want the date not the time. Can anyone help. I need this so I can compare old files to todays date in order to delete them thanks very much

Replies are listed 'Best First'.
Re: File Date on NT
by chromatic (Archbishop) on Jul 26, 2000 at 00:13 UTC
    You're halfway there. Get the access time of the file with stat -- that number is seconds since the epoch. You can pass that to localtime and get the date (in list context):
    my $atime = (stat($filename))[9]; my ($day, $month, $year) = (localtime($atime))[3, 4, 5]; $year += 1900; # localtime year is offset by 1900 my @m_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $month = $m_names[$month]; print "$filename last accessed on $day $month $year.\n";
Re: File Date on NT
by Corion (Patriarch) on Jul 26, 2000 at 00:29 UTC

    Of course, if all you are interested in is the file modification time, the -M and -A functions return the number of days since the file was last modified resp. accessed.

    Use it as follows (untested)

    if (-M $filename < 4) { print "The file $filename was accessed less than four days ago\n"; };