python压缩解压文件(天地图切片批量解压缩)

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()   #一定要关闭

 

posted @ 2020-06-12 15:41  木易GIS  阅读(279)  评论(0编辑  收藏  举报