在目录位置使用通配符并查找所有带有扩展名的文件 [英] using wildcard in the dir locations and find all files with an extension
问题描述
my @hex_locations = ("$FindBin::Bin/../../../project/platform-fsm9900_cdp-full/build-target/gnss-1.0.0",
"$FindBin::Bin/../../../project/platform-fsm9900_cdp-base/build-target/gnss-1.0.0");
我可以用下面的通配符在单行中指定它而不是这两行吗?"$FindBin::Bin/../../../project/platform-fsm9900_cdp-*/build-target/gnss-1.0.0"
instead of these 2 lines, can I specify it in single line with a wildcard as below? "$FindBin::Bin/../../../project/platform-fsm9900_cdp-*/build-target/gnss-1.0.0"
my @hex_dep_files;
sub find_dep_files {
my $F = $File::Find::name;
if ($F =~ /.d$/ ) {
push(@hex_dep_files,$F)
}
}
for my $loc (@hex_locations) {
find({ wanted => \&find_dep_files, no_chdir=>1}, $loc);
}
使用上面的 for 循环,我从 @hex_locations 获取所有 *.d 文件,我可以在单个函数中完成它而不是调用名为find_dep_files"的单独函数,我不想调用不同的函数从这个 for 循环,所以我不需要将数组 @hex_dep_files 定义为全局.
with above for loop, I am getting all the *.d files from the @hex_locations, can I do it in single function instead of calling a separate function called "find_dep_files", I don't want to call a different function from this for loop so I need not define the array @hex_dep_files as global.
感谢大家的帮助.
推荐答案
回答实际问题.
my @hex_dep_files;
for my $loc (@hex_locations) {
find({
no_chdir => 1,
wanted => sub {
my $F = $File::Find::name;
return if $F !~ /.d$/;
push @hex_dep_files, $F;
},
}, $loc);
}
或
my @hex_dep_files;
find({
no_chdir => 1,
wanted => sub {
my $F = $File::Find::name;
return if $F !~ /.d$/;
push @hex_dep_files, $F;
},
}, @hex_locations);
这篇关于在目录位置使用通配符并查找所有带有扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!