perl解压单个文件

perl untar single file

所以 运行 我的代码在这里出现问题,我不确定我到底做错了什么,我向它传递了它搜索文件的两个参数,但它总是不存在。

我把这个传给文件

perl restore.cgi users_old_52715.tar.gz Ace_Walker

它没有找到它存在的文件我向你保证。

#!/usr/bin/perl
use Archive::Tar;

my $tarPath    = $ARGV[0];
my $playerfile = $ARGV[1].".ini";



my $tar = Archive::Tar->new($tarPath);
if ($tar->contains_file($playerfile)) {
    $tar->read($tarPath);
    $tar->extract_file($playerfile, './' );
    print "Successfully restored $playerfile to production enviroment\n";
    exit 0;
}else{
    print $playefile." does not exist in this archive!\n";
    exit 0;
}

只需写 Scott Hunter's 作为答案:

Try using an absolute path instead of a relative one.

if( $tar->extract_file($playerfile, './'.$playerfile )){ 
  print "Successfully restored $playerfile to production enviroment\n";
}
exit 0;

man Archive::Tar :

$tar->extract_file( $file, [$extract_path] )
Write an entry, whose name is equivalent to the file name provided to disk. Optionally takes a second parameter, which is the full native path (including filename) the entry will be written to.