Create TarFile using python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • itzel

    #1

    Create TarFile using python

    I have a problem. I'm new in python and 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). I already found some
    information and i try to apply it, but my scripy doesn't work. The
    first problem is when I had tried to open the file that i want to
    group, a IO error appear:

    f = open(log, "r")
    IOError: [Errno 13] Permission denied: 'C:\\path"

    I previusly asigned to "log" the path of the archive that i want to
    group....

    could sombody helpme???.

  • Peter Maas

    #2
    Re: Create TarFile using python

    itzel wrote:
    I have a problem. I'm new in python and 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). I already found some
    information and i try to apply it, but my scripy doesn't work.
    Did you look here?:



    Peter Maas, Aachen

    Comment

    • Gerold Penz

      #3
      Re: Create TarFile using python

      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(sourc e_dir, destination):
      """
      :param source_dir: Source directory name.
      :param destination: Destination filename.
      (TAR-GZ-Archive *.tar.gz)
      """

      t = tarfile.open(na me = destination, mode = 'w:gz')
      t.add(source_di r, os.path.basenam e(source))
      t.close()

      return True


      Regards,
      Gerold
      :-)


      --
      _______________ _______________ _______________ _______________ ____________
      Gerold Penz - bcom - Programmierung
      gerold.penz@tir ol.utanet.at | http://gerold.bcom.at | http://sw3.at
      Ehrliche, herzliche Begeisterung ist einer der
      wirksamsten Erfolgsfaktoren . Dale Carnegie

      Comment

      • itzel

        #4
        Re: Create TarFile using python

        yes, i did. I'm checking the link in ASPN and I think that it'll works
        for "my problem" ....thanks a lot!! One more question... I'll need do
        it frecuently: add more directories into the same block. Is the same
        procedure?

        Thanks!!!

        ps. sorry about gramatic, I don't write english frecuently....


        Yu-Xi Lim ha escrito:
        Peter Maas wrote:
        >>
        It doesn't show him how to archive a directory.

        Comment

        Working...