Python3zip压缩解压简单使用
来源:互联网 发布:淘宝怎样套现信用卡 编辑:程序博客网 时间:2024/06/14 02:53
#!/usr/bin/python#coding:utf-8'''author:huhaicool@sina.comdate 2015-09-06version 1.0python 3.x'''import os,os.pathimport zipfiledef zip_dir(file_path,zfile_path): ''' function:压缩 params: file_path:要压缩的件路径,可以是文件夹 zfile_path:解压缩路径 description:可以在python2执行 ''' filelist = [] if os.path.isfile(file_path): filelist.append(file_path) else : for root, dirs, files in os.walk(file_path): for name in files: filelist.append(os.path.join(root, name)) print('joined:',os.path.join(root, name),dirs) zf = zipfile.ZipFile(zfile_path, "w", zipfile.zlib.DEFLATED) for tar in filelist: arcname = tar[len(file_path):] print(arcname,tar) zf.write(tar,arcname) zf.close()def unzip_file(zfile_path, unzip_dir): ''' function:解压 params: zfile_path:压缩文件路径 unzip_dir:解压缩路径 description: ''' try: with zipfile.ZipFile(zfile_path) as zfile: zfile.extractall(path=unzip_dir) except zipfile.BadZipFile as e: print (zfile_path+" is a bad zip file ,please check!")if __name__ == '__main__': #zip_dir(r'/tmp/xungou',r'/tmp/xungou.zip') unzip_file(r'/tmp/xungou.zip',r'/tmp/xungou')
阅读全文
0 0
- Python3zip压缩解压简单使用
- [Qt]简单使用 Zlib 库压缩/解压数据
- GZIP简单压缩与解压
- 简单的压缩、解压、查看
- 使用zlib压缩/解压文件
- 使用SevenZipSharp压缩、解压文件
- 使用C#压缩解压文件
- openresty使用gzip压缩解压
- SharpZipLib 的使用(压缩,解压)
- 使用压缩流压缩和解压数据
- 简单的Zip压缩与解压
- 流:简单的压缩和解压流程
- java 使用Apache ant.jar压缩解压zip--一种简单的实现
- 在VC开发中使用简单灵巧的压缩/解压工具包LiteZip/LiteUnzip
- Zip使用密码压缩解压使用
- 使用 WinRAR 制作自解压压缩包
- 转贴: 【python】使用zlib进行压缩解压
- 使用7z压缩解压数据
- dubbo2.5.3消费dubbox提供的服务报错
- tomcat配置的项目总是出现卡死的现象
- 处理html字符串符合json
- 索引深入理解索引提高查询速度的原因
- 小谈CSRF
- Python3zip压缩解压简单使用
- C语言中time函数和localtime获取系统时间和日期
- PAT甲级 1044
- TableLayout
- HTTPS静态服务搭建过程详解
- Ubuntu 安装 JDK 7 / JDK8 的两种方式 ubuntu 安装jdk 的两种方式
- 苹果公司透露Siri新发音引擎的内部原理
- Mysql数据库索引
- github设置添加SSH