Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

File::Find

Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.

Provides recursive directory traversal: find() and finddepth().

The find() function takes a hash ref of options (or a code ref) and a list of directories to search. It recursively visits each file/directory and calls the wanted() callback.

Synopsis

use File::Find;
find(sub { print "$File::Find::name\n" }, '/home');
find({
    wanted   => sub { print "$_\n" if -f },
    no_chdir => 1,
}, @directories);
finddepth(sub { rmdir $_ if -d }, '/tmp/tree');

Functions

find

Traverse a directory tree in top-down order, calling the wanted() callback for each file and directory. Sets $File::Find::name, $File::Find::dir, and $_ for each visited entry.

use File::Find;
find(sub { print "$File::Find::name\n" }, '/tmp');
find({ wanted => \&process, no_chdir => 1 }, @dirs);

finddepth

Traverse a directory tree in bottom-up (depth-first) order. Equivalent to calling find() with the bydepth => 1 option: directories are processed after their contents.

use File::Find;
finddepth(sub { print "$File::Find::name\n" }, '/tmp');