The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Filesys::Tree - Return contents of directories in a tree-like format

SYNOPSIS

  use Filesys::Tree qw/tree/;

  my $tree = tree('/path/to/directory');

$tree now holds something like:

  {
    a => {
           type     => 'd',
           contents => {
                         1 => {
                                type     => 'f',
                              },
         },
  }

In this example, there is one directory named "a", which has a file named "1".

And you can also do:

  use Filesys::Tree qw/tree/;

  my $tree = tree( {'max-depth' => 2} , '/path/to/directory');

See OPTIONS for a full list of options.

FUNCTIONS

tree

This is currently the only function in the module. It returns a tree-like representation of a directory (or a set of directories, if you ask real hard).

OPTIONS

all

All files (by default, files beginning with a dot are not returned). Default value is 0.

Get a tree including all files:

  my $tree = tree( { all => 1 } , 'path/to/directory/' );

max-depth

Sets the max-depth for recursion. A negative number means there is no max-depth. Default value is -1.

Get a tree with a max depth of 2:

  my $tree = tree( { 'max-depth' => 2 , 'path/to/directory/' );

directories-only

Do not list files. Default value is 0.

  my $tree = tree( { 'directories-only' => 1 } , 'path/to/directory/' );

full

Full path for each entry. Default value is 0.

Get a tree with full paths and prefixes:

  my $tree = tree( { 'full' => 1 } , 'path/to/directory' );

Follows links. Default value is 0.

Get a tree by following links:

  my $tree = tree( { 'follow-links' => 1 } , 'path/to/directory/' );

pattern

Only return filename matching pattern.

Get a tree where only files in all lowercase characters are included:

  my $tree = tree( { 'pattern' => qr/^[a-z]+$/ } , 'path/to/directory/');

exclude-pattern

Exclude files matching the pattern.

Get a tree excluding files with numeric names:

  my $tree = tree( { 'exclude-pattern' => qr/^\d+$/ } , 'path/to/directory/');

AUTHOR

Jose Castro, <cog@cpan.org>

BUGS

Please report any bugs or feature requests to bug-filesys-tree@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

tree(1).

COPYRIGHT & LICENSE

Copyright 2005 Jose Castro, All Rights Reserved.

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