【发布时间】:2014-11-02 06:34:47
【问题描述】:
我是 Perl 的新手,我正在尝试编写一个脚本来获取 tar 文件的路径,检查其中是否有 txt 文件,如果有,将文件提取到输出文件夹。这是我的代码:
#!/usr/bin/perl
use strict;
use warnings;
use Archive::Tar;
use File::Spec::Functions qw(catdir);
#checking if tar file contain a txt file, if yes extract it to a folder
my $tarPath = 'path/to/tarArchive';
my $tar = Archive::Tar->new($tarPath);
my @files = $tar->list_files;
my $output_dir = 'C:/output/path';
foreach my $file (@files) {
if ( $file =~ /txt$/ ) {
my $extracted_file = catdir( $fileName, $file );
my $extracted_path = catdir( $output_dir, $file );
$tar->extract( $extracted_file, $output_dir );
print $extracted_file;
}
}
exit 0;
当我运行这个脚本时,我收到一个错误:存档中没有这样的文件。
能否请您帮我理解我做错了什么以及正确的命令应该是什么?
【问题讨论】: