Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
sub del_old{ my $age = 60*60*24*7; # convert 7 days into seconds my $now = time(); # get current time # Delete files older than 7 days. opendir (DIR, "old") or die "Couldn't open directory, $!"; while (my $file = readdir DIR) { next if $file=~/^\./; if ($now-(stat $file)[9] > $age) { # file older than 7 days print "This $file wil be deleted\n"; } } closedir DIR; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete old files
by Corion (Patriarch) on Mar 17, 2014 at 19:03 UTC | |
by Anonymous Monk on Mar 17, 2014 at 19:21 UTC | |
by Corion (Patriarch) on Mar 17, 2014 at 19:30 UTC | |
by Anonymous Monk on Mar 17, 2014 at 19:56 UTC | |
by roboticus (Chancellor) on Mar 18, 2014 at 11:42 UTC | |
|
Re: Delete old files
by Anonymous Monk on Mar 17, 2014 at 19:11 UTC | |
by Anonymous Monk on Mar 18, 2014 at 09:05 UTC |