import sys
import os
import bz2
from bz2 import decompress
path = "M:/data/CMORPH_V1.0/unzip_example/zip"
un_path="M:/data/CMORPH_V1.0/unzip_example/unzip"
for(dirpath,dirnames,files)in os.walk(path):
for filename in files:
filepath = os.path.join(dirpath, filename)
newfilepath = os.path.join(un_path, filename.split('.')[0]+filename.split('.')[1])
with open(newfilepath, 'wb') as new_file, bz2.BZ2File(filepath, 'rb') as file:
for data in iter(lambda : file.read(100 * 1024), b''):
new_file.write(data)
转载本文请联系原作者获取授权,同时请注明本文来自夏江江科学网博客。
链接地址:http://blog.sciencenet.cn/blog-669638-1093087.html
上一篇:数据
下一篇:压缩文件,解压文件,并读取