zoukankan      html  css  js  c++  java
  • 解压文件夹python

    # _*_ 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(r'd:	empAndroid.zip',r'E:	empliuzhi')
    
        
  • 相关阅读:
    css 图片的无缝滚动
    有时间研究下这个
    js的类数组对象
    js的this什么时候会出现报错
    js前端分页
    js队列
    js前端处理url中的参数为对象
    随机看的一点代码
    js的callee和caller方法
    js的Object和Function
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/6930664.html
Copyright © 2011-2022 走看看