python zipfile

  

 

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

 

上一篇:boost::gil::static_transform用法的测试程序


下一篇:java解压压缩包工具类