grahm has asked for the wisdom of the Perl Monks concerning the following question:
"The key to this is the file test operator -M which returns the number of days old the given file is. Just the thing you needed."#!/usr/bin/perl -w use strict; my $file; my $dir_spec = '/home/archive/logs/old'; opendir(LOGDIR, $dir_spec) or die "Can't open $dir_spec: $!\n"; while ( defined($file = readdir(LOGDIR)) ) { if (-M "$dir_spec/$file" > 7) { unlink("$dir_spec/$file") or die "Can't delete $dir_spec/$file: $!\n"; } } closedir(LOGDIR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about - M
by mikeirw (Pilgrim) on Jun 30, 2002 at 00:54 UTC | |
|
Re: Question about - M
by Zaxo (Archbishop) on Jun 30, 2002 at 05:28 UTC | |
by merlyn (Sage) on Jun 30, 2002 at 16:33 UTC | |
|
Re: Question about - M
by Beatnik (Parson) on Jun 30, 2002 at 10:17 UTC |