shahjapan shahjapan - 4 years ago 173
Python Question

How to create full compressed tar file using Python?

How can I create a .tar.gz file with compression in Python?

Answer Source

To build a .tar.gz for an entire directory tree:

def make_tarfile(output_filename, source_dir):
    with tarfile.open(output_filename, "w:gz") as tar:
        tar.add(source_dir, arcname=os.path.basename(source_dir))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download