#!/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/).