sub PopulateTree { my $path = shift; my $hashref = shift; wlog("Looking in $path..."); $pathcount++; #Added to get rid of empty dirs my $fixedpath = TrimPath($path); unless (-d $fixedpath) { mkdir $fixedpath, 0777; push @badpaths, $path; wlog( "Bad path found. Marked for deletion." ); } my $dir = new IO::Dir; my @dirContents; unless ($dir->open($path)) { warn("Couldn't open directory $path: $!\n"); return undef; }; unless (@dirContents = $dir->read()) { warn("Couldn't read directory $path: $!\n"); return undef; }; # now look at each item and decide what to do with it if (($#dirContents == 1) && ($path ne $inDir)) { push @badpaths, $path; push @badpaths, $fixedpath; wlog( "Empty path found. Marked for deletion." ); } ITEM: foreach my $item (@dirContents) { if (($item eq '.') || ($item eq '..')) { next ITEM; }; if (-d $path.$item) { # it's a directory, create an item entry for it $hashref->{$item} = { Type => 'Dir', Contents => {} }; # get its contents unless (PopulateTree($path.$item.'/', $hashref->{$item}->{Contents})) { warn("PopulateTree failed"); return undef; }; } elsif (-f _) { # create an item entry for it $hashref->{$item} = { Type => 'File',}; } else { wlog("$path$item is not a directory or file."); }; }; return 1; };