Text::FileTree - convert a list of files with full paths to a tree
A file list can be organized in a number of ways. The two that most probably comes to mind is a "state free" way, where each file is listed with full path and doesn't depend on its context. The find command outputs files in this way.
find
There is also the "stateful" way of display file lists, where each file is sorted by its common parents. E.g., instead of
foo/bar foo/baz
you might have the following structure instead:
foo/ bar baz
This module does just that, converts a "plain" file listing in to the "stateful", directory sorted, way.
my $ft = Text::FileTree->new( ); my $ft_w32 = Text::FileTree->new( platform => 'Win32' );
Create a FileTree parser object. By default, it assume the files are in the platform native format, but this can be overriden. Internally, File::Spec is used, but by specifiying a platform parameter File::Spec::<platform> is used instead.
File::Spec::<platform
Load the file list from a file.
Load the file list from a filehandle (or a filename). Examples:
open(my $pipe, '-|', 'find', '/'); Text::FileTree->new->from_fh($pipe);
Latest released version is available through CPAN. Latest development version is available on github:
https://metacpan.org/pod/Text::FileTree
https://github.com/olof/Text-FileTree
We use Github for issue tracking and pull requests.
https://github.com/olof/Text-FileTree/issues
If you don't have an account on Github (or for other reason don't want to use Github), we are ok with bugs filed on rt.cpan.org as well.
This module does not separate between a file and a directory. This only affects leaf nodes, as you can deduce that a file with children is indeed a directory. This is unlikely to be fixed, as there is really no way of distinguish them in, say, the output from find. Often, you should be able to determine this by context: e.g. by giving find the -type f flag --- now all leaf nodes are regular files.
-type f
Copyright (c) 2012 - Olof Johansson <olof@cpan.org> All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Text::FileTree, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::FileTree
CPAN shell
perl -MCPAN -e shell install Text::FileTree
For more information on module installation, please visit the detailed CPAN module installation guide.