#导入文件操作模块 import os #获取当前目录树 fileLists=[] for root,dirs,files in os.walk("."): for name in files: fileLists.append(os.path.join(root,name)) #导入压缩模块 import zipfile #创建压缩文件 currentDirName=os.path.split(os.getcwd())[1]#获取当前目录名 zipFileName=(currentDirName+'.zip') zf=zipfile.ZipFile(zipFileName,'w',zipfile.zlib.DEFLATED) #写入目录树 for file in fileLists: zf.write(file) #关闭压缩文件 zf.close()