码迷,mamicode.com
首页 > 编程语言 > 详细

python zipfile

时间:2021-04-23 12:03:14      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:compress   python   eve   com   root   pytho   names   for   dir   

  

 

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()

 

python zipfile

标签:compress   python   eve   com   root   pytho   names   for   dir   

原文地址:https://www.cnblogs.com/dissipate/p/14690529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!