# -*- coding:u8 -*- import os import zipfile def unzip_file(zipfilename, unziptodir): “““ #zipfilename为要解压文件 #unziptodir为指定解压存放目录 ””” if not os.path.exists(unziptodir): os.mkdir(unziptodir, 0777) zfobj = zipfile.ZipFile(zipfilename) for name in zfobj.namelist(): name = name.replace('\\','/') if name.endswith('/'): p = os.path.join(unziptodir, name[:-1]) if os.path.exists(p): # 如果文件夹存在,则删除:避免有新更新无法复制 shutil.rmtree(p) os.mkdir(p) else: ext_filename = os.path.join(unziptodir, name) ext_dir= os.path.dirname(ext_filename) if not os.path.exists(ext_dir): os.mkdir(ext_dir,0777) outfile = open(ext_filename, 'wb') outfile.write(zfobj.read(name)) outfile.close() |
|
来自: 昵称23178714 > 《python脚本分享》