Java Site MenuProgramming SectionsMiscellaneous StuffConsultancy ServicesDownloadsFeedback Form


DirWalk - directory tree walker [Home]



NAME

DirWalk - directory tree walker


SYNOPSIS

 use DirWalk;
 my $walker = DirWalk->new( 'somedir' );
 $walker->walk( DIRFUNC => \&dirfunc,
                FILEFUNC => \&filefunc,
                USERVALUE => $val
 );
 sub dirfunc  { print "Val: $_[0] Dir: $_[1] (Mode: $_[2])\n"; }
 sub filefunc { print "Val: $_[0] Dir: $_[1] File: $_[2] (Mode: $_[3])\n"; }


AUTHOR

 Rob Quince (robq@fiendish-demon-co-uk)


DESCRIPTION

This package provides a top-down or a depth first tree walking capability. A user provided function is called for each directory and file found in the tree.


METHODS

new( 'directory' )
The object constructor for the package.

walk( %options )
Walks the tree associated with the calling DirWalk object calling the directory and file functions passed in the options hash to perform actions on the directories and files found. The references to the desired methods to call are passed as the values to the DIRFUNC and FILEFUNC options.

The walk can either be top-down if DEPTHFIRST option is a false value or not specified, or deepest first if DEPTHFIRST option is a true value. The USERVALUE option is a scalar (or ref of course) that is passed to each of the called functions as the first argument, thus an object or other useful value can be passed.

For each directory level, top-down walking first calls the given directory function, then, for each file, the file function, starting at the top-most directory, working its way down and across the tree.

Deepest-first walking traverses down to the lowest level of each sub-directory found in the top-most directory at the outset, then, for each file, calls the file function. The directory function is called prior to exiting each level.


[Fiendish Home]


Content of this page Copyright © Robert Quince 1996 - 2005.
Site Comments