[Pdx-pm] recursive IO::Dir

Eric Wilhelm enobacon at gmail.com
Thu Feb 18 11:40:41 PST 2010

# from Tom Keller
# on Thursday 18 February 2010 11:04:

>I need to be able to process files within a directory tree.

This will give you all of the files and directories under $topdir:

  my @paths = File::Fu->dir($topdir)->find(sub{1});

If your matcher sub returns true, the file is returned.  So for only the 

  my @files = File::Fu->dir($topdir)->find(sub{$_->is_file});

The filenames returned are File::Fu::File objects relative to wherever 
$topdir is relative to (i.e. absolute if $topdir is absolute.)

If you want an iterator instead of one big list, you can use the 
finder() method.

  my $iter = File::Fu->dir($topdir)->finder(sub{1});

  while(defined(my $path = $iter->())) {
    $path or next;


There is currently some better documentation for find(), finder(), and 
the knob in my svn trunk:


Issues of control, repair, improvement, cost, or just plain
understandability all come down strongly in favor of open source
solutions to complex problems of any sort.
--Robert G. Brown

More information about the Pdx-pm-list mailing list