python压缩解压文件

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、解压文件

 

posted on 2019-09-04 09:53  芦苇草鱼  阅读(317)  评论(0编辑  收藏  举报