Archiving directory without external tools?
Fredrik Lundh
fredrik at pythonware.com
Tue Dec 14 17:44:39 EST 2004
<iamlevis3 at 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>
More information about the Python-list
mailing list