Python压缩钦点文件及文件夹为zip

2019-10-12 20:14 来源:未知

代码:

def zipDir(dirpath,outFullName):
    """
    压缩指定文件夹
    :param dirpath: 目标文件夹路径
    :param outFullName: 压缩文件保存路径 xxxx.zip
    :return: 无
    """
    zip = zipfile.ZipFile(outFullName,"w",zipfile.ZIP_DEFLATED)
    for path,dirnames,filenames in os.walk(dirpath):
        # 去掉目标跟路径,只对目标文件夹下边的文件及文件夹进行压缩
        fpath = path.replace(dirpath,'')

        for filename in filenames:
            zip.write(os.path.join(path,filename),os.path.join(fpath,filename))
    zip.close()

 

 

Python压缩指定的文件及文件夹为.zip

TAG标签:
版权声明:本文由彩民之家高手论坛发布于编程技术,转载请注明出处:Python压缩钦点文件及文件夹为zip