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

解压文件夹python

时间:2017-06-01 20:58:07      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:python   else   base   read   listdir   print   join   mkdir   class   

# _*_ coding: utf-8 _*_

import zipfile
import shutil
import os
print os.getcwd()
basedir = os.path.dirname(__file__)

print os.path.dirname(os.path.dirname(__file__))


def unzip_file(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(/):
            print name
            os.mkdir(os.path.join(unziptodir,name))
        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()
def deledir():
    current_path = os.path.split(os.path.realpath(__file__))[0]
    current_filelist = os.listdir(current_path)
    for f in current_filelist:
        if os.path.isdir(f):
            real_folder_path = os.path.join(current_path,f)
            try:
                for root,dirs,files in os.walk(real_folder_path):
                    for name in files:
                        del_file = os.path.join(root,name)
                        os.remove(del_file)
                    shutil.rmtree(real_folder_path)
if __name__ == __main__:
    
    unzip_file(rd:\temp\Android.zip,rE:\temp\liuzhi)

    

 

解压文件夹python

标签:python   else   base   read   listdir   print   join   mkdir   class   

原文地址:http://www.cnblogs.com/liuzhipenglove/p/6930664.html

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