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";
    
} # }}}
Github repository PerlModules, path: /File/Find/script.pl
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";

} # }}}
Github repository PerlModules, path: /File/Find/no_chdir.pl
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;
}
Github repository PerlModules, path: /File/Find/preprocess.pl

See also

determine depth level with preprocess and postprocess
Perl modules.
shell command: find
The Python function os.walk (that is in the os module).

Index