# encoding=utf-8 import zipfile import os def unzip_file(zipfilename, unziptodir): if not os.path.exists(unziptodir): os.mkdir(unziptodir) zfobj = zipfile.ZipFile(zipfilename,‘r‘) for name in zfobj.namelist(): name = name.replace(‘\\‘,‘/‘) print(name) if name.endswith(‘/‘): os.mkdir(os.path.join(unziptodir, name)) else: ext_filename = os.path.join(unziptodir, name) print(‘ext_filename=‘+ext_filename) ext_dir= os.path.dirname(ext_filename) print(‘ext_dir=‘+ext_dir) print(‘\n‘) if not os.path.exists(ext_dir): os.mkdir(ext_dir) data = zfobj.read(name) outfile = open(ext_filename, ‘wb‘) outfile.write(data) outfile.close() if __name__ == ‘__main__‘: unzip_file(‘.\\quantdo_page.zip‘,‘.\\‘) #在当前文件夹下进行解压,解压到当前路径
时间: 2024-11-06 04:57:37