Steve Sanbeg > Directory-Iterator-1.001 > Directory::Iterator

Download:
Directory-Iterator-1.001.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.001   Source  

NAME ^

Directory::Iterator - Simple, efficient recursive directory listing

SYNOPSIS ^

  use Directory::Iterator;

  my $it = Directory::Iterator->new($dir, %opts);
  while (my $file = <$it>) {
    print "$file\n";
  }

DESCRIPTION ^

This is a simple, efficient way to get a recursive list of all files under a specified directory.

It implements a typical iterator interface, making it simple to convert code that processes a list of files to use this instead. The directory is read as the list is consumed, so memory overhead is minimal.

This module loads the appropriate backend; either Directory::Iterator::PP or Directory::Iterator::XS. With the pure-perl backend, the speed is equivalent to File::Find; the XS backend is a few times faster, particularly on systems which implement _DIRENT_HAVE_D_TYPE (mainly Linux and BSD).

As a bit of syntactic sugar, the module also implements a constructor which forwards options to the backend; i.e.

 my $list = Directory::Iterator->new($dir, show_dotfiles=>1);

Is equivalent to

 my $list = Directory::Iterator->new($dir);
 $list->show_dotfiles(1);

METHODS

Currently, both back ends support the following options:

next()

Advance to the next file and return its name; returns undef after all names have been read. This is the underlying method for the <> operator.

get()

Return the latest file name without advance to the next file; returns undef after all names have been read. This is the underlying method for the "" operator.

prune()

Close the directory that is currently being read, so no more files from it will be returned.

As currently implemented, it's possible that some subdirectories could've been queued before the first file was seen, so it's not guaranteed that a single call to prune will always suffice. Its purpose is simply to be more efficient than continuing to read files from an unwanted directory.

To skip over a subdirectory with a single call, use show_directories and prune_directory.

show_dotfiles(ARG)

If ARG is true, hidden files & directories, those with names that begin with a . will be processed as regular files. By default, such files are skipped.

show_directories(ARG)

If ARG is true, directories will be returned from the list, in addition to being queued to process their files.

is_directory

Returns true if the most recently returned file entry is a directory; used to enable quickly differentiating directories form plain files.

prune_directory

Removes the most recently queued directory, and returns the name of the removed directory. This allows the module to quickly skip over subdirectories entirely, without ever opening them.

recursive(ARG)

If ARG is false, just look in the top-level directory; don't queue subdirectories for processing.

EXPORT

None by default.

SEE ALSO ^

Directory::Iterator::PP

Directory::Iterator::XS

File::Find

AUTHOR ^

Steve Sanbeg

COPYRIGHT AND LICENSE ^

Copyright (C) 2012 by Steve Sanbeg

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

syntax highlighting: