Archiving directory without external tools?

Discussion in 'Python' started by iamlevis3@hotmail.com, Dec 14, 2004.

  1. Guest

    Does Python have any internal facility for creating recursive archives
    of a directory? I'd like to avoid reliance on extenal tools
    (winzip,tar,etc).

    Thanks!
     
    , Dec 14, 2004
    #1
    1. Advertising

  2. <> wrote:

    > Does Python have any internal facility for creating recursive archives
    > of a directory? I'd like to avoid reliance on extenal tools
    > (winzip,tar,etc).


    import os, sys, zipfile

    directory = sys.argv[1]

    zip = zipfile. ZipFile(directory + ".zip", "w")

    for path, dirs, files in os.walk(directory):
    for file in files:
    file = os.path.join(path, file)
    print file, "..."
    zip.write(file)

    print "done"

    tweak as necessary.

    (did you even look in the library reference, btw?)

    </F>
     
    Fredrik Lundh, Dec 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ALuPin
    Replies:
    1
    Views:
    521
    Ken Smith
    Oct 8, 2004
  2. phil hunt
    Replies:
    0
    Views:
    328
    phil hunt
    Jan 23, 2004
  3. bahoo

    recursively archiving files

    bahoo, Apr 9, 2007, in forum: Python
    Replies:
    1
    Views:
    236
    Larry Bates
    Apr 9, 2007
  4. Guest
    Replies:
    5
    Views:
    329
    Walter Wang [MSFT]
    Aug 27, 2007
  5. Replies:
    2
    Views:
    266
    James Kanze
    May 7, 2009
Loading...

Share This Page