CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Need Help with Delete Script!

 



scampbell
Deleted

Nov 30, 2000, 12:07 PM

Post #1 of 2 (180 views)
Need Help with Delete Script! Can't Post

I am new to this forum and to perl. I have this delete script that deletes files and subdirectories that is seven days old or older but my problem is that it needs to stop at a specific root directory. Can anyone help me plug in a function that will do this?
Here is the script.

#!c:/perl/bin/perl.exe

# Delete all files and empty directories which are older than $Old days and
# are owned by $Uid. Directories not owned by $Uid "protect" files and
# subdirectories which are $Uid-owned.

$Dir = "f:/Test/"; # THIS IS THE ROOT # DIRECTORY I WANT TO # KEEP
$Old = 0; # 14 days expiration time
$Oldsecs = $Old * 24 * 60 * 60;
$Now = time;
$Atimebytes = 0;
$Mtimebytes = 0;
$Onemeg = 1048576;

sub CLEAN {
local($dir) = $_[0];
local(@f);
local($f);

print "examining $dir\n";
if (!chdir($dir)) {
print stderr "Can't cd to $dir!\n";
return 0;
}
if (!opendir(DIR,".")) {
print stderr "Can't open directory .!\n";
chdir("..") | | die "Can't cd to ..!";
return 0;
}
@f = readdir(DIR);
while ($f eq "." | | $f eq "..") {


unlink($f);
print "by atime rule deleted file $f ($s[7] bytes)\n";
$Atimebytes += $s[7];
while ($s[9] < $Now - $Oldsecs)
#print "by mtime rule would have deleted file $f ($s[7] bytes)\n";
{ $Mtimebytes += $s[7];
}
}
chdir("..") &#0124; &#0124; die "Can't cd to ..!";
@s = stat($dir);
do
{
print ("deleted empty directory $dir\n");
}
while ($s[9] < $Now - $Oldsecs && rmdir($dir));
}



@t = localtime($Now);
printf "%d:%d %d/%d/%d clean-ftp logging begins\n",$t[2],$t[1],$t[4]+1,$t[3],
$t[5];
&CLEAN($Dir);
printf "by atime rule recovered %1.2fM\n",$Atimebytes/$Onemeg;
printf "by mtime rule would have recovered an additional %1.2fM\n",
$Mtimebytes/$Onemeg;
printf "%d:%d %d/%d/%d clean-ftp logging ends\n",$t[2],$t[1],$t[4]+1,$t[3],
$t[5];


Cure
User

Dec 3, 2000, 9:49 AM

Post #2 of 2 (180 views)
Re: Need Help with Delete Script! [In reply to] Can't Post

perldoc File::Path


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives