Perl递归遍历指定文件下的文件
发布时间:2020-12-15 23:40:26 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl -wuse strict;#use autodie;#use File::HomeDir; #第三方模块,不管在什么操作系统上都能进入指定用户的主目录my $parentDir = 'F:webperlperl programlittleCamp';my $partInfo = '.+.pl$'; #正则表达search_file($parentDir,$partInf
#!/usr/bin/perl -w use strict; #use autodie; #use File::HomeDir; #第三方模块,不管在什么操作系统上都能进入指定用户的主目录 my $parentDir = 'F:webperlperl programlittleCamp'; 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 $dirn"; my @files = readdir $dh; #标量上下文和列表上下文 foreach my $file (@files) { my $filePath = "$dir/$file"; if(($file =~ m#$partInfo#i) and (-f $filePath)) #-f 判断是否是文件 { print "$filePathn"; } if((-d $filePath) and ($file ne '.') and ($file ne '..')) #-d判断是否是目录 { &search_file($filePath,$partInfo); } } } system 'pause'; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |