Search notes:
Perl module File::Find
use warnings;
use strict;
use File::Find;
use File::Spec;
my $root_dir = shift;
print "\n";
find(\&file_find_callback, $root_dir);
sub file_find_callback { # {{{
print "\$File::Find::dir $File::Find::dir \n"; # directory containing file
print "\$File::Find::name $File::Find::name\n"; # path of file
print "\$_ $_\n"; # Name of the file (without path information)
print "relative path ". File::Spec -> abs2rel($File::Find::name, $root_dir), "\n";
print "\n";
} # }}}
Using no_chdir
in order to not descent into the directories:
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use File::Spec;
my $root_dir = shift;
find({ no_chdir => 1,
wanted => \&file_find_callback, },
$root_dir);
sub file_find_callback { # {{{
print "\$File::Find::dir $File::Find::dir \n";
print "\$File::Find::name $File::Find::name\n";
print "\$_ $_\n";
print "relative path ". File::Spec -> abs2rel($File::Find::name, $root_dir), "\n";
print "\n";
} # }}}
Using preprocess
:
use warnings;
use strict;
use File::Find;
use feature 'say';
find({preprocess => \&preprocess,
wanted => \&wanted},
'../..');
sub preprocess {
# Only files or directories that match
say "Preprocess $File::Find::dir: ", join " - ", @_;
return grep { m/o/ } @_;
}
sub wanted {
say $File::Find::name;
}