[Israel.pm] Directory Parsing

Georges EL OJAIMI g-ojaimi at cyberia.net.lb
Fri Aug 5 02:13:35 PDT 2005


Hello,

I have the following code to parse a directory and get its listing, how can I recusingly retrieve all the directory and subdirectory contenta and display their respective paths?


############ Start of Code

use strict;
use warnings;

my $dirname = "path_to_directory";
my $file;
my @file_list;
opendir(DIR, $dirname) or die "Can't opendir $dirname: $!\n";
while (defined($file = readdir(DIR))) {
    push @file_list, $file."\n" unless (($file eq ".") or ($file eq ".."));
}
closedir(DIR);
print $_ for sort @file_list;

############ End of Code




More information about the Perl mailing list