pythonlinuxtarfile

Python tarfile.extract func not extracting content of directory


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)

Solution

  • 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