in reply to Using directory handles in recursive functions
Then I realized that File::Find did everything I needed: have a look ad it.sub clean { my ($dir) = @_; opendir (DIR, $dir) or {warn "cannot opendir $dir" and return}; my (@subdirs, @files); map { push @subdirs, $_ if (-d "$dir/$_" && $_ !~ /\.|\.\./); push @files, $_ if (-f "$dir/$_"); } readdir(DIR); closedir(DIR); map {&clean("$dir/$_")} @subdirs; print "DIR - $dir\n"; foreach my $file (@files) { # do thing on each file } }
|
|---|