I want to (by using File::Find) first list all files in current directory, and after that jump to a subdirectory. Is it possible?
Perl File::Find: First list all files in directory and then jump to next dir?
1.7k Views Asked by marverix At
2
There are 2 best solutions below
0
On
There is preprocess callback that is called when directory is entered. It can be used for the task like this:
use File::Find;
my $directory = '.';
find({
wanted => sub {
# do nothing
},
preprocess => sub {
print "$File::Find::dir :\n", join("\n", <*>),"\n\n";
return @_; # no filtering
},
}, $directory);
It prints current directory name and list of files within. Note that preprocess is given all directory entries for filtering and they need to be returned.
Use the preprocess option to do the files in each directory before descending into subdirectories:
Though to avoid extra stats, it should be: