in reply to Re: How do i change the file names while untar?
in thread How do i change the file names while untar?

Thanks a lot Zaxo, I tried to rename but I am getting errors: my $tar = Archive::Tar->read('test.tar', 1) or die $!; $tar->rename($_, '/export/home/test/renametest') for $tar->list_files; print ("$_"); I am getting the errors: Can't call method "list_files" without a package or object reference. and similar message for rename...Any suggestions?
  • Comment on Re^2: How do i change the file names while untar?

Replies are listed 'Best First'.
Re^3: How do i change the file names while untar?
by Zaxo (Archbishop) on Sep 28, 2005 at 21:31 UTC

    Try omitting the compression flag since you are dealing with an uncompressed tarball, and call new as the constructor,

    my $tar = Archive::Tar->new('test.tar') or die $!;

    That will make $tar an Archive::Tar object whose methods will be found.

    After Compline,
    Zaxo

      Zaxo, I tried it and the split path does not work either on unix .

        my $tar = Archive::Tar->new('deploy.tar', 1) or die $!;
       $tar->rename($_, changepath($_)) for $tar->list_files; $tar->extract;
        sub changepath { chomp; my $path = $_;
        my ($volume, $directories, $file) = File::Spec->splitpath($path);
        my $dir = File::Spec->catpath($directories, '');
      $_=$dir; }
      THe same code works fine on win 32. I am getting files from windows into unix and then trying to do these operations. Do you think it would be better to rename while tarring itself on windows box? Is that possible? Thanks
      Zaxo, I tried it and the split path does not work either on unix . my $tar = Archive::Tar->new('deploy.tar', 1) or die $!; $tar->rename($_, changepath($_)) for $tar->list_files; $tar->extract; sub changepath { chomp; my $path = $_; my ($volume, $directories, $file) = File::Spec->splitpath($path); my $dir = File::Spec->catpath($directories, ''); $_=$dir; } THe same code works fine on win 32. I am getting files from windows into unix and then trying to do these operations. Do you think it would be better to rename while tarring itself on windows box? Is that possible? Thanks