Re: trouble with this code in deleting files older than 60 days
- From: anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel)
- Date: 25 Jul 2005 12:45:04 GMT
Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
> In article <1122055593.914958.125580@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> George Lewycky <gelewyc@xxxxxxxx> wrote:
>
> > My problem is trying to delete all files older than 60 days in the
> > directory /MLIM_data/archive/cmp through a Perl script.
[...]
> There is no need to shell out from Perl to find and delete old files:
>
> #!/usr/local/bin/perl
> #
> use warnings;
> use strict;
> use File::Find;
>
> my $now = time();
> my $then = $now - (60 * 24 * 60 * 60); # 60 days ago
> find(
> sub {
> my $t = (stat)[9]; #mtime
> unlink $_ if $t < $then;
> },
> 'MLIM_data/archive/cmp'
> );
Nothing wrong with it, but Perl has the -M file test which gives the
file age in days. So (untested)
find sub { -M >= 60 and unlink }, 'MLIM_data/archive/cmp';
should suffice.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.
- References:
- trouble with this code in deleting files older than 60 days
- From: George Lewycky
- Re: trouble with this code in deleting files older than 60 days
- From: Jim Gibson
- trouble with this code in deleting files older than 60 days
- Prev by Date: Argument list too long (keep reading, it's not the FAQ)
- Next by Date: Re: posting an array
- Previous by thread: Re: trouble with this code in deleting files older than 60 days
- Next by thread: Re: trouble with this code in deleting files older than 60 days
- Index(es):
Relevant Pages
|