Jeff 'japhy' Pinyan wrote:
> You could go over the entries from readdir() one at a time:
>
> opendir DIR, $dir or die "can't read $dir: $!";
>
> while (defined(my $file = readdir DIR)) {
> next if $file eq '.' or $file eq '..';
> my $full = "$dir/$file";
> # ...
> }
>
> closedir DIR;
This isn't successfully going through all of the files. Is the recursion perhaps
causing problems because DIR keeps getting redefined with each level of
recursion, or am I missing something else?
sub Purge {
my ($dir)=@_;
opendir(DIR,"$dir") or die "can't read $dir: $!";
while (defined(my $file = readdir DIR)) {
next if $file eq '.' or $file eq '..';
print "Parsing $file\n";
if ((-M "$dir/$file") > $cutoff) {
print " Purging $dir/$file\n";
system("rm -rf $dir/$file");
} elsif ( -d "$dir/$file" ) {
print " Recursing into $dir/$file\n";
&Purge("$dir/$file");
} else {
print " Ignoring $dir/$file\n";
}
}
closedir DIR;
}