解压文件夹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:\temp\Android.zip',r'E:\temp\liuzhi')
解压文件夹python的更多相关文章
- 基于Python——实现解压文件夹中的.zip文件
[背景]当一个文件夹里存好好多.zip文件需要解压时,手动一个个解压再给文件重命名是一件很麻烦的事情,基于此,今天介绍一种使用python实现批量解压文件夹中的压缩文件并给文件重命名的方法—— [代码 ...
- java批量解压文件夹下的所有压缩文件(.rar、.zip、.gz、.tar.gz)
// java批量解压文件夹下的所有压缩文件(.rar..zip..gz..tar.gz) 新建工具类: package com.mobile.utils; import com.github.jun ...
- C# 压缩、解压文件夹或文件(带密码)
今天梳理一下项目中用到的压缩.解压文件夹或文件的方法,发现因为需求不同,已经用了好几个不同组件.今天就好好整理记录下,别下次遇到需求又重头开始了. DotNetZip DotNetZip是一个开源的免 ...
- 遍历文件夹及其子文件夹下的.pdf文件,并解压文件夹下所有的压缩包
List<PDFPATH> pdfpath = new List<PDFPATH>(); List<string> ziplist = new List<st ...
- 【转载】.NET压缩/解压文件/夹组件
转自:http://www.cnblogs.com/asxinyu/archive/2013/03/05/2943696.html 阅读目录 1.前言 2.关于压缩格式和算法的基础 3.几种常见的.N ...
- 跨平台的zip文件压缩处理,支持压缩解压文件夹
根据minizip改写的模块,需要zlib支持 输出的接口: #define RG_ZIP_FILE_REPLACE 0 #define RG_ZIP_FILE_APPEND 1 //压缩文件夹目录, ...
- zip压缩与解压文件夹或文件
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
- 【Mac】解压文件夹中文乱码
Mac 用的英文系统,发现下载含中文的文件后,解压为乱码,如图所示: 解决方法: 下载一个解压软件:"The Unarchiver" 安装后设置下,如图: 之后设置压缩文件的默认打 ...
- C#使用SharpZipLib压缩解压文件
#region 加压解压方法 /// <summary> /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件,文件夹及其子级被忽略) /// </summary> // ...
随机推荐
- hdfs校验和
hdfs完整性:用户希望储存和处理数据的时候,不会有任何损失或者损坏.所以提供了两种校验: 1.校验和(常用循环冗余校验CRC-32). 2.运行后台进程来检测数据块. 校验和: a.写入数据节点验证 ...
- SQL SEVER数据库重建索引的方法
一.查询思路 1.想要判断数据库查询缓慢的问题,可以使用如下语句,可以列出查询语句的平均时间,总时间,所用的CPU时间等信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- 爬取豆瓣电影top250并存储到mysql数据库
import requests from lxml import etree import re import pymysql import time conn= pymysql.connect(ho ...
- 爬去豆瓣图书top250数据存储到csv中
from lxml import etree import requests import csv fp=open('C://Users/Administrator/Desktop/lianxi/do ...
- BZOJ 4491: 我也不知道题目名字是什么 RMQ
4491: 我也不知道题目名字是什么 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 317 Solved: 174[Submit][Status][ ...
- ABAP function group和Tomcat library重复加载问题
ABAP ABAP help文档里对**LOAD-OF-PROGRAM"的关键字是这样描述的: This event keyword defines the program construc ...
- groff - groff 文档排版系统前端
总览 (SYNOPSIS) groff [ -abehilpstvzCENRSUVXZ ] [ -wname ] [ -Wname ] [ -mname ] [ -Fdir ] [ -Idir ] [ ...
- js原型,原型链的理解
1.所有引用类型(函数.数组.对象)都拥有_proto_属性(隐式原型) 2.所有函数拥有prototype属性(显式原型)(仅限函数) 3.原型对象:拥有prototype属性的对象,在定义函数时就 ...
- WINDOWS-基础:Thread.Sleep(0)
我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢?思考下面这两个问题: 假设现在是 2008-4-7 12:00:00.000,如果我调用 ...
- 理解AttributeUsage类
类定义: // 摘要: // 指定另一特性类的用法. 此类不能被继承. [Serializable] [AttributeUsage(AttributeTargets.Class, Inherited ...