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

python 压缩文件夹

时间:2020-02-29 14:49:57      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:文件夹   %s   name   压缩   param   filename   path   目标   路径   

import os
import zipfile

def zipDir(dirpath):
    """
    压缩指定文件夹
    :param dirpath: 目标文件夹路径
    """
    outFullName = dirpath + .zip
    zip = zipfile.ZipFile(outFullName,"w",zipfile.ZIP_DEFLATED)
    for path,dirnames,filenames in os.walk(dirpath):
        fpath = path.replace(dirpath,‘‘)
        for filename in filenames:
            print(ziping %s % filename)
            zip.write(os.path.join(path,filename),os.path.join(fpath,filename))
    zip.close()


if __name__ == __main__:
    target = input(Input target foler: \n)
    zipDir(target)

 

python 压缩文件夹

标签:文件夹   %s   name   压缩   param   filename   path   目标   路径   

原文地址:https://www.cnblogs.com/wztshine/p/12382847.html

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