def ZipFiles(targetdir, ziparchivename):
'''Create a zip archive of all files in the target directory.
'''
#os.chdir(targetdir)
myzip = zipfile.ZipFile(ziparchivename, "w", zipfile.ZIP_DEFLATED)
if type(targetdir) == str:
for root, dirs, files in os.walk(targetdir):
for fname in files:
if fname != ziparchivename:
myzip.write(os.path.join(root,fname))
if type(targetdir) == list:
for fname in targetdir:
myzip.write(fname)
myzip.close()
myzip = zipfile.ZipFile(ziparchivename, "r", zipfile.ZIP_DEFLATED)
if myzip.testzip() != None:
print "Warning: Zipfile did not pass check."
myzip.close()
评论列表
文章目录