#!/usr/bin/perl -w use strict; use warnings; use File::Find; use Data::Dumper qw/ DumperX /; use vars qw/ $TR $TREE $ROOT %DEMDIRS/; die "YOU CANNOT use/require ".__FILE__ if caller(); $ROOT = shift @ARGV; $TREE = $TR = ["$ROOT"]; &find( { wanted => \&build_tree, preprocess => \&Pre, postprocess => \&Post, bydepth => 0, # don't override ,} , $ROOT, ,); print DumperX($TREE) if @ARGV > 1; print "\n"; DumpTree($TREE); exit; sub Post { $DEMDIRS{$File::Find::dir} = $TR; # warn "post $File::Find::dir"; } sub Pre { my @it = sort { -d $b <=> -d $a } @_; return @it; } sub build_tree { if( $_ eq '.' or $_ eq '..') { return; } if(-d) { my $tTR = [$_]; if(exists $DEMDIRS{$File::Find::dir}) { $TR = $DEMDIRS{$File::Find::dir}; } $DEMDIRS{$File::Find::dir} = $TR; push @$TR, $tTR; $TR = $tTR; return; } push @$TR, $_; } sub DumpTree { my $ARRAY = shift or die "hello?"; my $DEPTH = shift || 0; # only 0 the first time my $atWhat = shift || 0; print shift(@$ARRAY), "\n" unless $DEPTH; my $FILE_OR_REF; while(defined($FILE_OR_REF = shift(@$ARRAY))) { if(ref $FILE_OR_REF) { if($DEPTH) { print Depthy($DEPTH,$atWhat); print "\n"; print Depthy($DEPTH, $atWhat); } else { print "\n"; } print '+'; print '---'; print shift(@$FILE_OR_REF); print "\n"; DumpTree($FILE_OR_REF, $DEPTH + 1, $atWhat + 1); next; } else { if($DEPTH) { print Depthy($DEPTH, $atWhat); } else { print '| '; } print $FILE_OR_REF; print "\n"; } } } sub Depthy { my $depth = shift; my $opy = shift || 0; my $string; for my $i (1..$depth) { if($opy) { $string .= '|'; $string .= ' ' x 3; } else { $string .= ' ' x 4; } } return $string; } __END__
## READMORE FOLLOWS
F:\dev\File_Tree>perl tree.pl F:\dev\File_Tree F:\dev\File_Tree | tmon.out | tree2.pl | tree.pl | tree2 | echo | dumptree.pl | tree.pl.bak +---b | file | | +---c | | file | | | | +---d | | | file +---a | aabcccfile | file | bbcccfile | | +---234 | | +---b | | bcccfile | | FILE | | | | +---a | | | FILE | | | | | | +---AAAAAADIRRRRRR | | | | | | +---DIRRRRRR | | | | file | | | | | | +---b | | | | FILE | | | | | | | | +---c | | | | | FILE | | | | | | | | | | +---d | | | | | | FILE | | | | | | | | | | | | +---f | | | | | | | FILE | | | | +---b | | | file | | | | | | +---c | | | | file | | | | | | | | +---d | | | | | file | | | | +---c | | | cfile | | | ccfile | | | cccfile | | | | | | +---d | | | | dfile | | | | | | | | +---e | | | | | efile +---echo0 +---File | fily.txt | | +---Tree | | Tree.pm | | Makefile.PL | | README | | test.pl | | Changes | | MANIFEST ### I INVITE YOU TO MAKE THE OUTPUT LOOK MORE LIKE ### AND AN EXTRA ++ IF YOU DO IT WITHOUT BUILDING THE ARRAY :) F:\dev\File_Tree>tree /a /f . F:\DEV\FILE_TREE | echo | dumptree.pl | tmon.out | tree2.pl | tree.pl | tree2 | tree.pl.bak | +---File | | fily.txt | | | \---Tree | Tree.pm | Makefile.PL | README | test.pl | Changes | MANIFEST | +---echo0 +---a | | bbcccfile | | aabcccfile | | file | | | +---b | | | bcccfile | | | FILE | | | | | +---c | | | | cfile | | | | ccfile | | | | cccfile | | | | | | | \---d | | | | dfile | | | | | | | \---e | | | efile | | | | | +---b | | | | file | | | | | | | \---c | | | | file | | | | | | | \---d | | | file | | | | | \---a | | | FILE | | | | | +---b | | | | FILE | | | | | | | \---c | | | | FILE | | | | | | | \---d | | | | FILE | | | | | | | \---f | | | FILE | | | | | +---DIRRRRRR | | | file | | | | | \---AAAAAADIRRRRRR | \---234 \---b | file | \---c | file | \---d file F:\dev\File_Tree>

In reply to tree.pl - kinda like tree by crazyinsomniac

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.