2013年(1)
分类: PERL
2013-07-08 12:37:44
脚本功能类似于linux的find遍历目标目录下的所有目录以及文件,找到想要的文件与目录
#!/opt/ActivePerl-5.12/bin/perl
use strict;
use Cwd;
my $from_dir = shift @ARGV; #从什么目录开始查找
my $tag = shift @ARGV; #要查找目录或者文件名
&search($from_dir,$tag);
sub search
{
my $source_dir = shift @_;
my $tag = shift @_;
©dir($source_dir);
print "search end!!\n";
sub copydir
{
my $up_dir = shift @_;
chdir $up_dir;
my @mydir = <$up_dir\/*>;
my @myfile = <*>;
my $fileindex = -1;
for $a (@mydir){
$fileindex++;
#print "$a\n";
next if (-l $a);
if (-d $a){
if ( $myfile[$fileindex] eq $tag ){
my $path = getcwd;
print "-- searched dir ->$myfile[$fileindex]<-\n";
print "-- path = $path\/$myfile[$fileindex]\n\n";
}
©dir($a);
}else{
if ( $myfile[$fileindex] eq $tag ){
my $path = getcwd;
print "-- searched file ->$myfile[$fileindex]<-\n";
print "-- path = $path\/$myfile[$fileindex]\n\n";
}
}
}
}
}