def __un_zip(self, file_path):
"""解压.zip格式文件到同名目录下,若解压之前就存在该目录说明已解压,跳过解压过程,返回该目录"""
zip_file = zipfile.ZipFile(file_path)
file_dir = file_path.split(".zip")[]
if os.path.isdir(file_dir):
return file_dir
else:
os.mkdir(file_dir)
for names in zip_file.namelist():
zip_file.extract(names, file_dir)
zip_file.close()
return file_dir def __un_tar(self, file_path):
"""解压.tar.gz格式文件到同名目录下,若解压之前就存在该目录说明已解压,跳过解压过程,返回该目录"""
tar = tarfile.open(file_path)
names = tar.getnames()
file_dir = file_path.split(".tar.gz")[]
if os.path.isdir(file_dir):
return file_dir
else:
os.mkdir(file_dir)
for name in names:
tar.extract(name, file_dir)
tar.close()
return file_dir

补充

def extractall(file_dir, to_dir):
for root, dirs, names in os.walk(file_dir):
for name in names:
file_path = os.path.join(root, name)
if file_path.endswith(".gz") or file_path.endswith(".zip") or file_path.endswith(".rar"):
unzip_file_path = os.path.join(to_dir, name)
Archive(file_path).extractall(unzip_file_path, auto_create_dir=True)
# os.remove(file_path)
file_dir = unzip_file_path
# to_dir=to_dir
# extractall(file_dir, to_dir)

  

最新文章

  1. Vs2012 创建项目失败 未找到与约束ContractName
  2. [hadoop] hadoop-all-in-one-伪分布式安装
  3. MATLAB处理信号得到频谱、相谱、功率谱
  4. Win7安装visual c++ 2015 redistributable x64失败
  5. [转]Ionic – Mobile UI Framework for PhoneGap/Cordova Developers
  6. 配置Java EE Eclipse+Tomcat开发环境
  7. 猫都能学会的Unity3D Shader入门指南
  8. jquery学习笔记(4)--实现table隔行变色以及单选框选中
  9. <php>json小结
  10. Java的HashCode
  11. javascript实现图片无缝滚动(scrollLeft的使用方法介绍)
  12. EFCore Lazy Loading + Inheritance = 干净的数据表 (一) 【献给处女座的DB First程序猿】
  13. 枪弹辩驳(弹丸论破)即将登陆PC
  14. IntelliJ IDEA(四) :Settings(上)
  15. CentOS6.5系统,mysql数据库的安装
  16. bc 命令
  17. yolo2详解
  18. zsh与oh-my-zsh
  19. SpringMVC实现多文件(批量)上传
  20. 【linux系列】Centos下安装mysql数据库

热门文章

  1. 启动欢迎页面时,Android Studio设置全屏Activity
  2. string部分方法
  3. 配置Beyond Compare作为比较和合并工具
  4. quartz的job怎么获取Spring上下文
  5. [Oracle][RAC]Oracle RAC环境里打OCW上的个别Patch,然后Rollback,发现OCW也被Rollback掉了
  6. SVG路径PATH
  7. Codeforces Round #309 (Div. 1) A(组合数学)
  8. git一些有用的命令
  9. 有关导出Excel特殊字符的问题
  10. c#的默认访问权限