All pastes #2127843 Raw Edit

recursive directory list

public text v1 · immutable
#2127843 ·published 2012-03-13 16:05 UTC
rendered paste body
my $path = ".";
get_list($path);

sub get_list
{
    my $path = shift;

    opendir(my $dh, $path) or die "Cannot open dir $path: $!\n";
    while (my $f = readdir($dh))
    {
        next if $f =~ m/^\.{1,2}$/;

        if (-d "$path/$f")
        {
            get_list("$path/$f");
        }
        else
        {
            print "$path/$f\n";
        }
    }
    closedir($dh);
}



Implemented:
    my $path = $mainconfig->val( 'Icinga','configpath'  )."/twill/walkthrough";
    my $hostlist=get_list($path, []);
    sub get_list {
        my ($path, $hostlist) = @_;
        opendir(my $dh, $path) or die "Cannot open dir $path: $!\n";
        while (my $f = readdir($dh)){
            next if $f =~ m/^\.{1,2}$/;
            next if $f =~ m/^\.svn$/;
            if (-d "$path/$f"){
                get_list("$path/$f", $hostlist);
            }else{
                push @$hostlist, "$path/$f";
            }
        }
        closedir($dh);
        return $hostlist;
    }

print Dumper $hostlist;
exit;