Create TarFile using python

Gerold Penz gerold.penz at
Tue Sep 12 23:03:28 CEST 2006

itzel schrieb:
> I need a script that group a
> list of files using Tar file utility and then, compress that block
> using a compress utility (gzip i think).


This script packs all files and directories inside the ``source_dir`` 
into the TAR-GZ-Archive (``destination``):

   import os.path
   import tarfile

   def to_tar_gz(source_dir, destination):
       :param source_dir: Source directory name.
       :param destination: Destination filename.
                           (TAR-GZ-Archive *.tar.gz)

       t = = destination, mode = 'w:gz')
       t.add(source_dir, os.path.basename(source))

       return True


Gerold Penz - bcom - Programmierung
     gerold.penz at | |
Ehrliche, herzliche Begeisterung ist einer der
     wirksamsten Erfolgsfaktoren. Dale Carnegie

More information about the Python-list mailing list