标签:文件夹 %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)
标签:文件夹 %s name 压缩 param filename path 目标 路径
原文地址:https://www.cnblogs.com/wztshine/p/12382847.html