heezy has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have been using Archive::Tar for a while and I love it, it makes creating tar archives really simple. Except for one thing...

I am adding files to it with a path something like..

/apps/webroot/service/servicelist/ss/filename.blah

However when stored in the tar file I only want the path info stored like...

/servicelist/ss/filename.blah

You see at the moment it's storing the path from the root into the archive that Archive::Tar produces. I don't want this, just the path structure after the /service directory.

When I hand the files to other users it has the /apps/webroot/service section at the start that I do not need/want!

My script is being run from a completly different directory on the server /apps/servicelist/change-history and that is also where I would like the new tar files to appear

Here is the code I am using if anyone is interested..

my $tar = Archive::Tar->new(); foreach $updatedFile (@updatedFiles){ print "Adding to tar ($updatedFile)\n"; $tar->add_files("$updatedFile"); } foreach $newFile (@newFiles){ print "Adding to tar ($newFile)\n"; $tar->add_files("$newFile"); } $tar->write("$tarFile");

Can anyone suggested a way of overcoming this?

Thanks

M

Replies are listed 'Best First'.
Re: Changing path length using Archive::Tar
by steves (Curate) on Feb 09, 2003 at 23:40 UTC

    One way I've done this is to use Archive::Tar's add_data method. I read the file into a scalar which becomes add_data's second argument. I then use stat to populate a hash for the third argument. The first argument becomes the name I want to file to take on.

    One thing I haven't tried that may work for you: If you want relative path names (no leading slash in your example then) have you tried using chdir to first change to the relative leading directory, then adding relative file names?

      If you are on win make sure you binmode before you suck in the file for add_data.

      -Waswas