Although I think that also sweeps sub directories too.#!perl -w use strict; use File::Find; my $days = 12 * 7; # twelve weeks, seven days a week. sub DeleteOldFiles { return 0 unless -M > $days; unlink $_ or die $!; return 1; } find( \&DeleteOldFiles, '.' );
Update
Hmmm, File::Find is really for delving into the subdirs, and if you don't want that, then just glob(*) like this:
By the way, -M returns days since last modified, -A returns days since last accessed. I wasn't sure what your purpose was, but recently accessed files might be useful.#!perl -w use strict; my $days = 12 * 7; # twelve weeks, seven days a week. while( <*> ) { next if -d; unlink $_ or die $! if -M > $days; }
As for speed issues, you have to loop over everyfile, no matter what, the only question is the efficiancy of the loop. Well, do as little as possible in the loop. Calculate the age aforehand, and short circuit where you can.
In reply to Re: Deleting Files
by Adam
in thread Deleting Files
by BatGnat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |