in reply to Re: Delete on age of files Help!
in thread Delete on age of files Help!

Hi, even this doesnt work:
#!/usr/bin/perl -w use strict; use File::stat; my $mytime=(time); my $file_stat; ... opendir(DIR, $all_session) or die "Couldn't open directory, $!"; while (my $sessions = readdir DIR) { # Use a regular expression to ignore files beginning with a peri +od next if ($sessions =~ m/^\./); next if ($sessions !~ /^cgisess_[a-f0-9]{32}$/); #if( -M qq{$all_session/$sessions} > 360){ # 6 minutes #print "Del these session files: $sessions<br>"; #} if ($file_stat = (stat $sessions)[9]){ if ($file_stat >= ($mytime - 300)) { print "File older than 5min found. The file name is $ses +sions"; last; } } } closedir DIR; ...

Replies are listed 'Best First'.
Re^3: Delete on age of files Help!
by Marshall (Canon) on Jan 17, 2011 at 19:06 UTC
    stat returns something different:
    stat[ 9 ] is an absolute time (from epoch).
    Perl: Stat