My question is like: when use:
import tarfile
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()
if the file before compress called "sampleFolder", after I doing the above steps, how to return the "sampleFolder" name, better with its full path, or how to set the result to other name like "Folder"?
it's not a good question, but I actually have demand on this in my project.
I have to edit the question to: if I don't know the "sampleFolder", can I get a return to it after the decompress step
It will be extracted to the working directory by default:
So, the path to the extracted data is:
To extract in a different location:
edit: If you just want to know the name
"sampleFolder"
contained in the archive, it's not necessary to extract somewhere. You should usegetnames
:Note that tarballs can have multiple files or folders within.