NAME
Trav::Dir - Traverse directories
SYNOPSIS
use FindBin '$Bin';
use Trav::Dir;
my $o = Trav::Dir->new (
# Don't traverse these directories
no_trav => qr!/(\.git|xt|blib)$!,
# Reject these files
rejfile => qr!~$|MYMETA|\.tar\.gz!,
);
my @files;
chdir "$Bin/..";
$o->find_files (".", \@files);
for (@files) {
if (-f $_) {
print "$_\n";
}
}
produces output
./lib/Trav/Dir.pm
./lib/Trav/Dir.pod.tmpl
./lib/Trav/Dir.pod
./Makefile.PL
./t/trav-dir.t
./build.pl
./make-pod.pl
./examples/synopsis-out.txt
./examples/synopsis.pl
./MANIFEST.SKIP
./Changes
./.gitignore
(This example is included as synopsis.pl in the distribution.)
VERSION
This documents version 0.00_01 of Trav-Dir corresponding to git commit 865d2bc925f3552e97c6d4782b62f1b23000f414 released on Wed Feb 17 22:03:02 2021 +0900.
DESCRIPTION
Traverse directory structure. Replacement for "File::Find".
METHODS
find_files
$o->find_files ($dir, \@files);
new
my $o = Trav::Dir->new (%options);
- callback
-
Callback when file is found. Can be undefined.
&callback ($data, $file);
Here $file is the full path of the file.
- maxsize
-
Maximum file size to consider.
- minsize
-
Minimum file size to consider.
- no_dir
-
Don't include directories in the results.
- no_trav
-
Regex to reject directories to traverse.
- preprocess
-
Regex to preprocess a list of files.
- only
-
Regex to accept only files which match it.
- rejfile
-
Regex to reject files which don't match it.
SEE ALSO
- File::Find
-
This is a Perl version of the Unix "find" utility. It is part of the Perl core so is installed with Perl by default. Instead of passing variables to callbacks as subroutine arguments, it passes them using
$_
and oddly-named pseudo-global variables like$File::Find::dir
and$File::Find::name
. Callbacks have no avenue for passing user-defined data, so one has to either use global variables or anonymous subroutine closures. The module's documentation also notes that it has given things the wrong name, within the documentation.Trav::Dir started out as basically a script I had written so that I didn't have to use File::Find again. After writing this module, I then went back and replaced the uses of File::Find with this, so there are some similarities.
AUTHOR
Ben Bullock, <bkb@cpan.org>
COPYRIGHT & LICENCE
This package and associated files are copyright (C) 2021 Ben Bullock.
You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.