Create TarFile using python

Gerold Penz gerold.penz at tirol.utanet.at
Tue Sep 12 17:03:28 EDT 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).

Hi!

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 = tarfile.open(name = destination, mode = 'w:gz')
       t.add(source_dir, os.path.basename(source))
       t.close()

       return True


Regards,
Gerold
:-)


-- 
________________________________________________________________________
Gerold Penz - bcom - Programmierung
     gerold.penz at tirol.utanet.at | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
     wirksamsten Erfolgsfaktoren. Dale Carnegie



More information about the Python-list mailing list