#!/usr/bin/perl -w
use strict;
#use autodie;
#use File::HomeDir; #第三方模块,不管在什么操作系统上都能进入指定用户的主目录
my $parentDir = 'F:\web\perl\perl program\littleCamp';
my $partInfo = '.+\.pl$'; #正则表达
&search_file($parentDir, $partInfo);
sub search_file
{
my ($dir, $partInfo) = @_;
#print $partInfo, "\n";
opendir my $dh, $dir or die "Cannot open dir $dir\n";
my @files = readdir $dh; #标量上下文和列表上下文
foreach my $file (@files)
{
my $filePath = "$dir/$file";
if(($file =~ m#$partInfo#i) and (-f $filePath)) #-f 判断是否是文件
{
print "$filePath\n";
}
if((-d $filePath) and ($file ne '.') and ($file ne '..')) #-d判断是否是目录
{
&search_file($filePath, $partInfo);
}
}
}
system 'pause';
Perl递归遍历指定文件下的文件
最新推荐文章于 2024-08-01 14:29:28 发布