--- 1177457.pl 2016-12-08 12:36:42.215747438 +0100 +++ 1177457.pl.new 2016-12-08 12:45:35.603768833 +0100 @@ -2,7 +2,7 @@ use strict; use warnings; - +use File::Spec; ### This program looks at the current directory and then makes a path to all the sub directories. @@ -22,17 +22,20 @@ sub list { my $path=$_[0]; #print "DEBUG - listing [$path]\n"; - chomp(my @files = `ls -a $path`); + my @files = do { + opendir my $dh, $path or die "opendir '$path': $!\n"; + grep !/^\.\.?$/, readdir $dh; + }; my @dirs; foreach(@files) { - if (-d "$path/$_" && $_ ne "." && $_ ne ".."){ - push (@dirs , "$path/$_"); - } + my $f = File::Spec->catpath($path,$_); + push @dirs, $f if -d $f; } print "-------------------------------------\n"; print "Generating HTML doc for path = [$path]\n"; - open(FHOUT, ">", "$path/index.html") - or die "Can't open '$path/index.html':$!\n"; + my $index = File::Spec->catpath($path,'index.html'); + open(FHOUT, ">", $index) + or die "Can't open '$index':$!\n"; print FHOUT ""; print FHOUT "
" . "##
foreach (my @dirs) {
&list($_);
}