码迷,mamicode.com
首页 > 编程语言 > 详细

python解压zip

时间:2016-06-02 16:29:03      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

 

 

# 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,.\\)     #在当前文件夹下进行解压,解压到当前路径
   

 

python解压zip

标签:

原文地址:http://www.cnblogs.com/harstanber/p/5553398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!