#!/usr/bin/perl -w use Cwd; use Getopt::Std; use vars qw($opt_d); getopt('d'); local $start_dir = ($opt_d) ? $opt_d : getcwd; print "\n"; listDir($start_dir); print ("\n\nfinished.\n\n"); sub listDir { local $thisdir = $_[0]; print "\n$thisdir:\n"; opendir THISDIR, $thisdir; #get all entries, filter in directories # then filter out .. and . local @allentries = readdir THISDIR; local @directories = sort grep !/^\.\.?$/, (grep -d, @allentries); local $entry = ""; closedir THISDIR; foreach $entry(@allentries) { print "\t$entry\n"; } foreach $entry (@directories) { chomp($entry); &listDir($thisdir . '/' . $entry ); } }