import zipfile
import os
src_path = r"D:\test\testdir"
dsc_path = r"D:\test\testdir.zip"
extr_path = r"D:\test\new_testdir"
#压缩文件
z = zipfile.ZipFile(dsc_path , "w")
for root, dirs, files in os.walk(src_path):
for file in files:
z.write( os.path.join( root, file ) )
z.close()
#解压文件
with zipfile.ZipFile(dsc_path, mode="a") as f:
f.extractall(extr_path)
f.close()
1、源文件
2、压缩文件
3、解压文件