Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date comparing

Status
Not open for further replies.

Zippeh

Programmer
Sep 24, 2002
56
GB
I need to find all the files in a directory that havent been modified in the past 7 days. I've got my script to so far find the last modified time using the following:
Code:
use File::Find;
my $age;

@ARGV = qw(.) unless @ARGV; #Darllen o'r current directory os dim paramedr

find(\&nolFfeil, @ARGV);


sub nolFfeil {
	$age = (stat($_))[9];
	print "$age\n";	
}
I know it isn't pretty! How can I use the $age variable in order to delete the file if it hasn't been modified in 7 days?

Many thanks :)
 
Code:
if ($age < (time()-(86400*7))) {
  print "File should be deleted";
}
Something like that, not TESTED
--Paul
 
Code:
if (-M $_ < 8 ) {
   print scalar localtime((stat($_))[9]), "n";
}

assumes you are in the directory where $_ is or it has the full path to the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top