0

I am using the tarfile module to compress the image files. But when I compress the images it retain the total path for the images where they are placed. They should be relative. Means if the Images are placed at location a/b/c/demo_images.png then after extracting the tar.gz it contains the folder also in the extracted part like the same structure a/b/c/demo_images.png but I need only demo_images.png after extraction.

tar = tarfile.open(os.path.join(self.image_folder,"Images.tar.gz"),"w:gz")
    for f in image_list:
        tar.add(f,recursive=False)
        try:
            os.unlink(f)
        except OSError as e:
            self.testlog.error(e.errno)
     tar.close()
Sagar
  • 2,315
  • 7
  • 25
  • 34

1 Answers1

0
tar.add(f, arcname=os.path.basename(f), recursive=False)
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98