NAME

File::Walker - Perl extension for blah blah blah

SYNOPSIS

use File::Walker;

my $walker = File::Walker->new( { start => $dir } );

my $name;
while (defined $name = $walker->step())
  {
  print "At $name\n";
  }
print "dirs: ", $walker->dirs()," files: ", $walker->files(),"\n";
$walker->reset();
while (defined $name = $walker->step())
  {
  plast if $name eq 'foo';	# find file/dir foo
  }

DESCRIPTION

File::Walker is the complement to File::Find: instead of calling a callback for each file system entry it let's you call an interator function to step through the entries.

This allows for defered walking of the file tree, and also for early abort (for instance, if you already found the file you were looking for).

METHODS

new()

my $walker = File::Walker->new( $args );

Creates a new File::Walker object with the following (optional) arguments in a hash ref:

start		Starting dir, defaults to '.'
skip		String with list of items to skip as:
		  d - directories
		  f - files
		  l - symlinks
		  0 - zero-byte long files
		The skip option defaults to 'l'.

If you pass skip = 'fdl'>, all items would be actually skipped, so step() will return undef on the first call.

reset

$walker->reset();

Resets the File::Walker object, e.g. resets the iterator to the starting dir, sets the count of directories and files to 0 etc.

step

my ($name) = $walker->step();

Walks the file tree one step and returns the name of the next entry. Returns undef if there are no more entries.

dirs

print "Seen so far: ", $walker->dirs(), " directories.\n";

Returns the number of directories (or folders) seen so far. . and .. do not count.

files

print "Seen so far: ", $walker->files(), " files.\n";

Returns the number of files (as opposed to directories) seen so far.

level

my $level = $walker->level();

Returns the current level we are in. Going into a sub-directory increases the level by one, going up decreases the level.

start

my $start = $walker->start();

Returns the start directory.

steps

print "Did ", $walker->steps(), " steps so far.\n";

Returns the number of times step() was called.

current

my $item = $walker->current();

Returns the current item, e.g. the same name as the last call to $walker-step()> did return. If step() was not called before, will return the same as $walker-start()>.

curdir

my $item = $walker->curdir();

Returns the current directory we are in.

BUGS

  • Does completely ignore symlinks.

SEE ALSO

File:Find

AUTHOR

Copyright (C) 2004 by Tels http://bloodgate.com/

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.