How can I recursively read out directories in Perl?
Posted
by Przemek
on Stack Overflow
See other posts from Stack Overflow
or by Przemek
Published on 2010-03-19T09:01:00Z
Indexed on
2010/03/19
9:01 UTC
Read the original article
Hit count: 237
Hi,
I want to read out a directory recursively to print the data-structure in an HTML-Page with Template::Toolkit. But I'm hanging in how to save the Paths and Files in a form that can be read our easy.
My idea started like this
sub list_dirs{
my ($rootPath) = @_; my (@paths);
$rootPath .= '/' if($rootPath !~ /\/$/);
for my $eachFile (glob($path.'*')) {
if(-d $eachFile)
{
push (@paths, $eachFile);
$paths[$i] = &list_dirs($eachFile);
}
else
{
push (@files, $eachFile);
}
}
return @paths; }
How could I solve this problem?
© Stack Overflow or respective owner