Python tarfile.extract func not extracting content of directory

700 Views Asked by At

I'm trying to extract a directory from tarfile using python. But some/ALL of its files inside that directory are missing after extraction. Only pathname got extracted (ie, I get folder home inside /tmp/myfolder but its empty)

Code is as follwing:

for tar in tarfiles:
    mytar = tarfile.open(tar)
    for file in mytar:
         if file == "myfile":
               mytar.extract('home', /tmp/myfolder)
1

There are 1 best solutions below

0
Harpreet On BEST ANSWER

Found a fix, by default extract only extracts path of variable, I can get content with

tar.extractall(members=members(tar))

Reference: https://stackoverflow.com/a/43094365/20223973