Perl Basics
Introduction to Perl
FAQ's
CGI
Regular Expressions

PC Overview
Cool Stuff
My Modules
Success Stories
Links
Perl in the News
Logos
Perl @ msn
Perl Chat

PC Internals
About
Contact
Guest Book
Handy Logos
What's new

Delete ?older than? Script

See also
P-friendly

[ home ] - [ search ] - [ sitemap ]

Document has moved.











up


#!/usr/bin/perl -w
use strict;

die "Age in days! --> cleanup 60 1\n" unless $ARGV[0];
die "Prefix! --> cleanup 60 1\n" unless $ARGV[1];

print "Deleting files older than $ARGV[0] days with prefix $ARGV[1]!...\n";
sleep(3);

opendir(D, ".") or die $!;

my $time = time();

while (my $f = readdir(D)) {
	next if $f =~ /^\./;
	next unless $f =~ /^$ARGV[1]/;

	my ($atime, $mtime, $ctime) = (stat($f))[8..10];
	my $age_hours = ($time - $mtime) / 3600;
	my $age_days  = int($age_hours / 24);

	next unless $age_days > $ARGV[0];
	
	print "---> Deleting $f ($age_days days)...";
	unlink $f;
	print " done\n";
}

closedir(D);
home - feedback - search - web jobs
© 1998-2004 retoh :)