给大家推荐一下perl
tree_show.pl#!/usr/bin/perl
sub list_dir{
if(-f $_){
my @names=split "/",$_;
if($_<0){
print "$names[@names-1] is just a file.\n";
return;
}else{
if($_==0){
print " " x $_,"|\n";
print " " x $_,"+","-" x 2;
print "$names[@names-1]\n";
}else{
my $c=$_/2;
print "|" x $c,"|\n";
print "|" x $c,"+","-" x 2;
print "$names[@names-1]\n";
}
return;}
}
else{
if(-R $_ and -O $_){
my @names=split "/",$_;
if($_ eq "/"){
print "/\n";}
elsif(length($_)>1 and substr($_,-1,1) eq "/")
{print "",substr($_,0,length($_)-1),"\n";}
elsif($_ ne "/" and $_<0){
print "$names[@names-1]\n";
}else{
if($_==0){
print " " x $_,"|\n";
print " " x $_,"+","-" x 2;
print "$names[@names-1]\n";}
else{
my $c=$_/2;
print "|" x $c,"|\n";
print "|" x $c,"+","-" x 2;
print "$names[@names-1]\n";
}
}
opendir DH,$_ or return;
my @files=readdir DH;
closedir DH;
for(my $i=0;$i<@files;$i++){
next if $files[$i] eq "." or $files[$i] eq "..";
if($_ eq "/"){
list_dir("/$files[$i]",$_+2);}
elsif($_ eq "../" or $_ eq "./" or substr($_,-1,1) eq "/")
{list_dir("$_$files[$i]",$_+2);}
else{list_dir("$_/$files[$i]",$_+2);
}
}
}}
}
list_dir($ARGV,-2);
服务器上的超过一半的脚本是用的perl。有时间研究一下。 回复 kevin.zhang 的帖子
过年回家跟我弟学的!我的脚本水平一般!过奖了
页:
[1]