以下脚本将所有文件和目录存储在数组 @file_list
中.
如何仅过滤带有 .lt6
的文件扩展名,仅此而已?
opendir (CURRDIR, $localdir);
@file_list = grep !/^\.\.?$/, readdir CURRDIR;
print STDOUT "Found Files: @file_list\n";
干杯
最佳答案
尝试这个:
grep(/\.lt6$/i, readdir(CURRDIR))
我已经用过很多次了。它有效,尽管现在我更喜欢使用 File::Next对于这种事情。
例子:
use File::Next;
my $iter = File::Next::files( { file_filter => sub { /\.lt6$/ } }, $localdir )
while ( defined ( my $file = $iter->() ) ) {
print $file, "\n";
}
关于perl - 如何根据扩展名过滤文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/552414/