Select a batch of files from a path pattern(only the last folder changes)

来源:互联网 发布:阿里云ftp文件上传 编辑:程序博客网 时间:2024/05/17 01:44
sub SelectFiles($$$$;$$){
my ($srcPathPattern, $srcFile, $desPath, $desFile) = @_;
my $srcPath = dirname($srcPathPattern);
my $folderPattern = basename($srcPathPattern);
#print "$srcPathPattern, $srcPath, $folderPattern\n";
my @folders;
opendir DH, $srcPath or die("Can't open dir: $srcPath\n");
foreach my $folder(readdir DH) {
#print "\none file in $srcPath is $folder\n";
if($folder =~ /$folderPattern/){
push(@folders, $folder);
}
}
@folders = sort @folders;
#print "@folders\n";
closedir(DH);


my @files;
foreach(@folders){
my $dirTmp = PathConnection($srcPath, $_);
#print "$dirTmp\n";
opendir DH_Tmp, $dirTmp or die("Can't open dir: $dirTmp\n");
foreach my $file(readdir DH_Tmp) {
#print "one file in $dirTmp is $file\n";
if($file =~ /$srcFile/){
my $fullpathfile = PathConnection($dirTmp, $file);
push(@files, $fullpathfile);
}
}
closedir(DH_Tmp);
}
@files = sort @files;
#print "@files\n";
return $TRUE;
}
原创粉丝点击