I have a tar file I want to extract with libarchive to a specific directory. How can I make libarchive extract into to any directory I want? At the moment it always extracts into my program’s working directory. I looked at this answer but all this does is change the location of an archive entry within the archive, i.e. it still extracts into my program’s working directory just at a different sub-directory.
Share
From the libarchive discussion boards:
"It depends, of course, on the archive being extracted.
Typically, you would chdir() to the directory where you want the output to go, then use code similar to that in the Wiki Examples page:
A Complete Extractor Example
or in the untar.c sample program:
untar Example
Of course, if the tar file you’re extracting has
interesting filenames (such as "c:\someotherdirectory"),
then you’ll need to play with the filenames as you extract.
Note that the examples all use archive_read_next_header()
to get an entry object from the input archive describing
the next entry; you are then free to edit that entry description
in any way you wish — in particular, you can change the
name, owner, or permissions — before calling
archive_write_header() to recreate the entry on
disk.
The Examples page in the Wiki above is probably the
best place to start."