0

I have tried a couple of different spins on in it, but do not appear to be getting any results. Below are two attempts at extracting the contents of a .tar.gz archive to the same folder where the compressed archive is;

For example I would start with just test_file.tar.gz in my Windows folder and end up with test_file.tar.gz, plus it's extracted contents.

The print statements show the code looping through the archive correctly in the first method, however I cannot see any extracted contents.

What am I doing wrong?

import tarfile
import os
import sys

    full_path = 'C:\Myfolder\test_file.tar.gz'

    if (full_path.endswith("tar.gz")):
        tar = tarfile.open(full_path, "r:gz")

        for item in tar:
            print(item)
            tar.extract(item)
        tar.close()


        with tarfile.open(full_path) as tar:
            print(full_path)
            tar.extractall()        
            tar.close()
gdogg371
  • 3,879
  • 14
  • 63
  • 107

1 Answers1

1

I checked your code, everything is normal except indent...

But please check your folder where you execute script or change

tar.extractall('c:\\Path\\To\\Extract') 
Omrum Cetin
  • 1,320
  • 13
  • 17
  • thank you. yes as per comment above the contents had exported to the location where the Python script was and not where the .tar.gz files were. I will include a path to extract to as per you answer. – gdogg371 Jun 07 '19 at 23:15