Search code examples
linuxperlarchive-tar

perl untar single file


So running into an issue with my code here not sure what exactly i'm doing wrong i pass it the two arguments it searches for the file but its always going to does not exist.

i pass this to the file

perl restore.cgi users_old_52715.tar.gz Ace_Walker

its not finding the file it exist i assure you.

#!/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;
}

Solution

  • Just writing Scott Hunter's comment as an answer:

    Try using an absolute path instead of a relative one.