/foo/bar
baz
Extracting the contents of baz
in the archive to /foo/bar
The archive contains:
baz/ file1.txt
The source directory contains:
foo/ bar/ file2.txt
After extraction I want it to be:
foo/ bar/ file1.txt file2.txt
Extract to a temporary directory and then move the contents of baz
to the target location, this works since I the baz
directory will always have the same name.
Any other ideas?
You could use the tarfile library's extract()
, extractall()
or extractfile()
methods. You should be able to access non-top-level objects in the archive this way.
Just note that the path
in extractall() is not the path inside the archive, but rather the path you want to extract it to, so putting baz there will not help.
You'll probably have first call getmembers()
then pare the list down to what you want, then call one of the above extract methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With