Reputation: 4560
I am trying to tar a folder using the following code.
make_tarfile('logs_' + str(datetime.datetime.now()),logFolder)
def make_tarfile(output_filename, source_dir):
with closing(tarfile.open(output_filename, "w:gz")) as tar:
tar.add(source_dir, arcname=os.path.basename(source_dir))
I dont see any tar file created though.Please could any one correct my code.
Thanks in advance
Upvotes: 0
Views: 255
Reputation: 44092
tarfile.open
, you have to specify the extension .tar.gz
if you want to see it as name of the archive.with closing
is not necessary in Python 2.7+, you may use with tarfile.open(output_filename, "w:gz")) as tar:
as open tarfile has proper context manager available.Upvotes: 1