[thelist] Perl Problem.

Michael Percy mpercy at portera.com
Mon Aug 28 17:35:17 CDT 2000


Try this:
-------------------------------------------------
#!perl -w

# get the time now and set time limit
my $dir = 'c:/my/directory/here/';
my $now = time;
my $secs = 18000;

#get the file and delete as appropriate
opendir (TEMP, $dir);
foreach (readdir(TEMP)) {
	# If the filename does not end in .save and +5 hrs old, kill it
	if ( (!( /\.save$/ || /^(\.|\.\.)$/ )) && (-f "${dir}/${_}") ) {
		my @stats = stat("${dir}/${_}");
		my $atime = $stats[8];
		print "$_ $atime\n";
		if (($now - $atime) > $secs) {
			unlink("${dir}/${_}");
			print("Killed: ${dir}/${_}\n");
		}
	}
}
closedir (TEMP);
-------------------------------------------------

Regards,
Michael Percy

> -----Original Message-----
> From: Peter Bancroft [mailto:pdb103 at york.ac.uk]
> Sent: Sunday, August 27, 2000 4:28 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Perl Problem.
> 
> 
> A problem a friend has with a perl problem.. unfortunately, 
> my Perl really
> isn't very good.  Any of you know the problem?  Algian says thanks in
> advance :)
> -Peter
> 
> #get the time now and set time limit
> my $now = time;
> my $secs = 18000;
> 
> #get the file and delete as appropriate
> opendir(TEMP, "c:/my/directory/here/");
>  for (readdir(TEMP)) {
>   if ($_ =~ /.save/g || $_ eq "." || $_ eq "..") {;}
>   else {
>    my $atime = (stat "c:/my/directory/here/$_")[8];
>    print "$_ $atime ";
>    if (($now - $atime) > $secs) {
>     unlink("c:/my/directory/here/$_");
>    }
>   }
>  }
> closedir(TEMP);
> 
> the problem is in the $atime. I made the perl print out the 
> $_ which is the
> name of a file
> and the atimeof that file (atime being the last time the file 
> was accessed.
> the problem is that for the 2 files in that directory is that 
> they both give
> me the same atime and i know for a fact that one of those 2 
> files hasn't
> been accessed for at least 1.5 months. and i tried using other files i
> haven't accessed and it still won't work. Does anyone have 
> any clue why this
> is? I've been trying to change the code here and there but it 
> still gives
> the same result the atime doesn't change for some reason so 
> the files with
> over 5 hours are never deleted.
> 
> 
> 
> 
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt ! 
> 





More information about the thelist mailing list