I'm looking for a way to compress a tar file in a tar.gz without directory.
Today my code generate a TAR file without directory with "tarfile" library and arcname arguments but when I want to compress this TAR file in TAR.GZ I don't understand how to delete directory.
I have made many tests in the last 3 days.
My code :
Tarname = example.tar
ImageDirectory = C:\...
TarDirectory = C:\..
tar = tarfile.open(Tarname, "w")
tar.add(ImageDirectory,arcname=TarName)
tar.close()
targz = tarfile.open("example.tar.gz", "w:gz")
targz.add(TarDirectory, arcname=TarName)
targz.close()
Try using the gzip module : Here is an example of how to use it :
For individual file(s):
for each file that you want to add.
basename
will strip the directory information.Or, for a recursive directory: