- 论坛徽章:
- 0
|
&printDirTree('TestDir');
sub printDirTree {
my $curr_dir = $_[0];
# print the 'root' dir
if (!$_[1]) {
print "$curr_dir\n" ;
$_[1] = '';
}
# get all entries in current dir except '.' '..'
opendir DIR, $curr_dir or die "Cannot open $curr_dir: $!\n";
my @files = grep { !/^(\.|\.\.)$/ } (readdir DIR);
closedir DIR;
for (0..$#files) {
my $pre = $_[1];
if ($_ < $#files) {
print $pre, '├─', $files[$_], "\n";
$pre .= '│ ';
}
else {
print $pre, '└─', $files[$_], "\n";;
$pre .= ' ';
}
if (-d "$curr_dir/$files[$_]") {
&printDirTree("$curr_dir/$files[$_]", $pre);
}
}
} |
在Win下和tree的图形效果一致.
TestDir
├─Dir_1_1
│ ├─Dir_2_1
│ │ ├─input.txt
│ │ └─Copy of input.txt
│ ├─Dir_2_2
│ ├─input.txt
│ ├─Copy of input.txt
│ └─Z1
│ └─Z2
├─Dir_1_2
│ ├─Dir_2_1
│ │ └─input.txt
│ ├─Dir_2_2
│ │ └─Z1
│ │ └─Z2
│ └─Dir_2_3
├─Dir_1_3
│ ├─Dir_2_1
│ ├─Dir_2_2
│ │ ├─input.txt
│ │ └─Copy of input.txt
│ ├─input.txt
│ └─Copy of input.txt
└─Z1
└─Z2
[ 本帖最后由 Lonki 于 2007-10-13 11:33 编辑 ] |
|