[Pdx-pm] recursive IO::Dir alternatives

Tom Keller kellert at ohsu.edu
Thu Feb 18 13:09:05 PST 2010


Summary for modules to traverse a directory tree:
0. q(don't roll your own. ... I know that, just needed the exercise.)
1. File::Next
2. File::Fu
3. File::Find::Object
4. File::Finder
5. File::Find

thanks,
Tom
kellert at ohsu.edu<mailto:kellert at ohsu.edu>
503-494-2442







On Feb 18, 2010, at 11:40 AM, Eric Wilhelm wrote:

# 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
files:

 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;
   do_something_with($path);
 }

http://search.cpan.org/~ewilhelm/File-Fu-v0.0.6/lib/File/Fu/Dir.pm#finder

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

 http://svn.scratchcomputing.com/File-Fu/trunk/lib/File/Fu/Dir.pm

--Eric
--
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
---------------------------------------------------
   http://scratchcomputing.com
---------------------------------------------------
_______________________________________________
Pdx-pm-list mailing list
Pdx-pm-list at pm.org
http://mail.pm.org/mailman/listinfo/pdx-pm-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/pdx-pm-list/attachments/20100218/6e261f23/attachment-0001.html>


More information about the Pdx-pm-list mailing list