Forum Moderators: coopster & phranque

Message Too Old, No Replies

auto delete script question

only delete files older than 30 days

         

stcrim

6:18 pm on Jan 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Been using this to delete files:

#!/usr/bin/perl
$path="/www/mysite/mailreader/temp";
opendir(FP,"$path");
@del=readdir(FP);
closedir(FP);
foreach $i (@del) {
unlink "$path/$i";
}

looking for a little help to have it only delete files older than 30 days...

Or another script that will do the same thing

Any thoughts

-s-

stcrim

6:29 pm on Jan 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The goal with the above is just to keep a few directories with logs tidy...

-s-

Brett_Tabke

6:44 pm on Jan 27, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



[perl]
#!/usr/bin/perl

$ThirtyDays = 60*60*24*30; #60secs x 60mins * 24hrs * 30 days
$ThirtyDaysAgo = time - $ThirtyDays;

$path="/www/mysite/mailreader/temp";
opendir(FP,"$path");
@del=readdir(FP);
closedir(FP);
foreach $i (@del) {
$fp = "$path/$i";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($fp);

unlink "$fp" if ($mtime < $ThirtyDaysAgo);
}
[/perl]