Wrote this 'cause I couldn't get the tree program online to work on my computer.
#!/usr/bin/perl use Term::ANSIColor; use Getopt::Long; my $depth = 0; my $directory = "."; my $totaldir = 0; my $totalfile = 0; my %CONFIG = (); my $output = 'STDOUT'; Getopt::Long::Configure ("bundling_override"); GetOptions(\%CONFIG, 'n=i', 'c', 'r', 'o', 'L'); if (exists($CONFIG{'o'})) { $CONFIG{'o'} = 'tree_dir'; $output = <FILE>; open($output, ">$CONFIG{'o'}") or die "Can't open $output : $!"; } if (!(-d $ARGV[0]) && ($ARGV[0])) { print "Directory does not exist.\n"; print "Exiting\n"; exit; } else { $directory = (!$ARGV[0] ? "." : $ARGV[0]); print "\nAtlasing \"$directory\" and it's sub-directories.\n\n"; } &tree($directory); sub tree { my (@directory, @dirs, @files); my $i = 0; chdir "$_[0]"; chomp(@directory = glob("*")); $depth++; foreach my $cur (@directory) { (-d $cur) ? push(@dirs, $cur) : push(@files, $cur); } $totaldir += @dirs; $totalfile += @files; if ($CONFIG{'r'}) { (@dirs, @files) = reverse(@files, @dirs); } @directory = (@dirs, @files); foreach my $cur (@directory) { print $output "\n|" . (" " x ($depth-1)); if (exists($CONFIG{'n'}) and ($i >= $CONFIG{'n'}) and (!(-d $c +ur))) { print $output "+ " . (($#directory - $i) + 1) . " more fil +es in this directory"; last; } else { print $output "-"; print color((-d $cur) ? 'bold blue' : 'red') if ($CONFIG{ +'c'}); print $output $cur; print color 'reset'; print $output "\/" and tree($cur) if (-d $cur); if (exists($CONFIG{'L'}) && (!(-d $cur))) { $mtime = gmtime((@stat = stat($cur))[9]); print " $mtime"; } $i++; } } chdir ".."; $depth--; return; } print $output "\n\nTotal number of directories: $totaldir."; print $output "\nTotal number of files: $totalfile.\n"; close($output);

In reply to tree (Unix program) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.