sub scan { # scan and return all sub directories
my ($path) = @_;
my ($file, @dirs) = ();
my $dir = new IO::Dir $path;
my $dbpath = $path; $dbpath =~ s{^\./}{};
return () unless defined $dir;
while (defined($file = $dir->read)) {
next if $file =~ /^\.\.?$/;
if (defined($db{$file})) {
$db{$file} .= "\0" . $dbpath;
} else {
$db{$file} = $dbpath;
}
next if -l $file; # skip symbolic links
push(@dirs, "$path/$file") if -d "$path/$file";
}
$dir->close;
return @dirs;
}
sub descend {
my ($path) = @_;
foreach my $dir (scan($path)) {
descend($dir);
}
}
|