Archiving directory without external tools?

I

iamlevis3

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!
 
F

Fredrik Lundh

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top