import os
import zipfile
def get_image_from_zip(work_path):
'''
params work_path : zip file absolute path
to do : Unzip files from a zip
'''
if work_path.split('.')[-1] == 'zip':
zip_file = zipfile.ZipFile(work_path)
zip_list = zip_file.namelist()
for f in zip_list:
print(os.path.dirname(work_path))
if f.split('.')[-1] == 'gz': # get nii.gz file path from unzip files
nii_file_path = os.path.join(os.path.dirname(work_path), f)
zip_file.extract(f, os.path.dirname(work_path))
zip_file.close()
return nii_file_path
if __name__ == '__main__':
work_path = r'F:\xx\04dbc072002e88a4ca8c79cb193e66dd.zip'
get_image_from_zip(work_path)
Python zipfile 解压zip文件至当前文件夹
最新推荐文章于 2023-04-28 08:34:20 发布