python zipfile

时间:2021-04-23 12:03:14   收藏:0   阅读:0

  

 

import os, zipfile


def deflate(paths, zip_path):
    z = zipfile.ZipFile(zip_path, w, zipfile.ZIP_DEFLATED, allowZip64=True, compresslevel=9)
    for path in paths:
        path = os.path.normpath(path)
        if os.path.isfile(path):
            z.write(path, path.split(os.sep)[-1])
        elif os.path.isdir(path):
            for root, dirnames, filenames in os.walk(path):
                for filename in filenames:
                    full_path = os.path.join(root, filename)
                    arcname = full_path[len(path):].strip(os.sep)
                    z.write(path, arcname)

    z.close()

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!