On Thu, Nov 20, 2008 at 10:18, AndrewMcHorney <[EMAIL PROTECTED]> wrote:
> Hello
>
> I am working on a perl script that will go through a directory and it's
> subdirectories and purge all the files that are more than a specified number
> of days old. I am using a Unix system so I do a find command to gather up
> the files I want. I then am going to do a stat command to find the date the
> file was created (it is never modified) and then determine if it is to be
> deleted. What is the easiest way to determine if a date is more than x
> number of days old.
snip

You need File::Find* to get the file names, the -M** test to find out
how old they are, and the unlink*** command to delete them

Something like this

#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

my @dirs = qw(/private/tmp);

File::Find::find(
        sub {
                if (-M > 3) {
                        #unlink here instead of the print
                        print "$File::Find::name\n";
                }
        },
        @dirs
);


* http://perldoc.perl.org/File/Find.html
** http://perldoc.perl.org/functions/-X.html
*** http://perldoc.perl.org/functions/unlink.html
-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to