in reply to Deleting Files
How about something like:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Deleting Files
by McD (Chaplain) on Feb 24, 2001 at 02:57 UTC | |
by tilly (Archbishop) on Feb 24, 2001 at 03:47 UTC | |
Re: Re: Deleting Files
by BatGnat (Scribe) on Feb 23, 2001 at 08:34 UTC | |
by a (Friar) on Feb 23, 2001 at 11:20 UTC | |
by ashok (Sexton) on Feb 24, 2001 at 01:09 UTC | |
by a (Friar) on Feb 24, 2001 at 09:44 UTC |
In Section
Seekers of Perl Wisdom