By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

Archiving directory without external tools?

P: n/a
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!

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<ia*******@hotmail.com> 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>

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.