#!/usr/bin/perl -w
use strict;
my
($p,
$s,$d);
grep { #
/-.?s/&&##
$s++; /-.?d/
&&$d++;}@ARGV;
(($p = $ARGV[-1]
|| ".") !~ /^-/)||
($p=".");print"$p\n";
d($p,0,0);my$kr; sub d{
my($p,$x,$v)=@_;opendir(D,
$p)or warn"Can't read $p:$!"
;my@d;map {my($k,$r,$y,$l)=(#
"$p/$_", " ",($_ eq $d[-1]),'');
print map {($_ ? "|":" ") ." "x3}
(split(//,unpack("b*", $v)))[0..($x
- 1)];if(-l$k){$l = readlink($k);;$r=
' -> '.(-e$l?$l:"($l)");-l$k;}print $y?
'`':'|',"-- ",$s ?sprintf("[%9d] ",-s _):
'',$_,$r,"\n";if(!-l _&&-d _){vec($v,$x,1)=
!$y;d($k,$x+1,$v);};}(@d=sort grep{(-d"$p/$_"
||!$d)&&
!/^\./}#
readdir#
D);}#DMO
I found this one again while cleaning out my home directory, so I thought I'd share it. It's a partial work-alike for the UNIX 'tree' command I wrote four years ago for a local LUG's programming contest (see http://oclug.on.ca/pwars/April2001/).
In reply to Tree
by dave0
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.