Joel Berger > File-chdir-WalkDir-0.040 > File::chdir::WalkDir

Download:
File-chdir-WalkDir-0.040.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.040   Source  

NAME ^

File::chdir::WalkDir

SYNOPSIS ^

 use File::chdir::WalkDir

 my $do_something = sub {
   my ($filename, $directory) = @_;

   ...
 }

 walkdir( $dir, $do_something, qr/^\./ );
 # executes $do_something->($filename, $directory) [$directory is the folder
 # containing $filename] for all files within the directory and all 
 # subdirectories. In this case excluding all files and folders that 
 # are named with a leading `.'.

DESCRIPTION ^

This module is a wrapper around David Golden's excellent module File::chdir for walking directories and all subdirectories and executing code on all files which meet certain criteria.

FUNCTION ^

walkdir( $dir, $code_ref [, @exclusion_patterns, $opts_hashref ]);

walkdir takes a base directory (either absolute or relative to the current working directory) and a code reference to be executed for each (qualifing) file. This code reference will by called with the arguments (i.e. @_) containing the filename and the full folder that contains it. Through the magic of File::chdir, the working directory when the code is executed will also be the folder containing the file.

Optionally exclusion patterns may by passed which will exclude BOTH files AND directories (and hence all subfiles/subdirectories) which match any of the patterns. This use is discouraged in favor of the exclude option below.

An optional hash reference, passed as the last option to walkdir will process key-value pairs as follows:

Note: walkdir will act on symlinked files but not on symlinked folders to prevent unwanted actions outside the folder and to prevent infinite loops. To exclude symlinked files too add a line like return if (-l $filename); near the top of the code to be executed; this is an example of the fine exclusion mentioned above.

SOURCE REPOSITORY ^

http://github.com/jberger/File-chdir-WalkDir

AUTHOR ^

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2011 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: