1 c:\Perl\bin\perl.exe findfile.pl #!/usr/perl/bin/perl ##C:\\MIG-WORK\\Research\\SPOOL\\main open(OFH, ">C:\\MIG-WORK\\Research\\SPOOL\\result.txt") || die("cna't open the file\n"); open(SOFH, ">C:\\MIG-WORK\\Research\\SPOOL\\spoolresult.txt") || die("cna't open the file\n"); my $sqlcount =0; my $sqlspool=0; $PATH="C:\\MIG-WORK\\Research\\SPOOL\\main"; &SeeDir($PATH); print OFH "total sql :".$sqlcount."\n"; print OFH "spool sql :".$sqlspool."\n"; print "total sql :".$sqlcount."\n"; print "spool sql :".$sqlspool."\n"; print SOFH "total sql :".$sqlcount."\n"; print SOFH "spool sql :".$sqlspool."\n"; close(OFH); close(SOFH); sub SeeDir { my ($path,$DIR)=@_; if(chdir($path)) { opendir($DIR,$path)|| die "can't open directory directory $path"; my $line=readdir($DIR); while ($line) { if($line ne '.' && $line ne '..') { my $subpath = $path."\\".$line; if(chdir($subpath)) { print " **** $line ****\n\n"; SeeDir($subpath); } else { if($line=~/\.sql$/i) { $sqlcount++; #print " **** $line ****\n"; print OFH " **** $line ****\n"; my $sflag = &findspool($subpath); ##print $sflag."sflag **\n"; if($sflag > 0) { $sqlspool++; #print SOFH "-----$line------\n"; #print SOFH "-----------------\n"; } #print " **** $line ****\n\n"; #print OFH " **** $line ****\n\n"; } } } $line=readdir($DIR); } closedir($DIR); } } sub findspool { my $flag = 0; my ($file, $FHD) = @_; open(FHD, $file) || die("cna't open the $file\n"); while($fline = <FHD>) { chomp($fline); $fline=~s/^\s+|\s+$//g; if($fline=~/^spool/i) { print OFH "$fline\n"; print SOFH "$fline\n"; #print "$fline \n"; $flag =1; } } if($flag >0) { #print SOFH "-----------------\n"; } close(FHD); return $flag; } 2 c:\Perl\bin\perl.exe findfile.pl #!/usr/perl/bin/perl $PATH="C:\\MIG-WORK\\Research\\SPOOL\\main\\"; push (my @dirs, $PATH); while(@dirs) { my $rcdir = shift @dirs; opendir(DIR,$rcdir) or die "can't open dir $rcdir \n"; while(my $name = readdir(DIR)) { chomp($name); if($name!~/^\./) { my $filename = $rcdir.$name; if(-f $filename) { #print $filename." :file\n"; } else { push (@dirs, $filename."\\"); print $filename." :folder \n"; } } } } http://bbs.csdn.net/topics/20470253 http://www.mail-archive.com/perlchina@googlegroups.com/msg02611.html