python解压TAR文件至指定文件夹的实例

yipeiwu_com6年前Python基础

如下所示:

######### Extract all files from src_dir to des_dir
def extract_tar_files(src_dir,des_dir):
  files = os.listdir(src_dir)
  for file in files:
    dir_tmp = os.path.join(src_dir, file)
    print dir_tmp
    if not os.path.isdir(dir_tmp): ##是文件,非文件夹
      #解压特定文件
      if dir_tmp.endswith("gz") and (dir_tmp.find(cs.Port_week_perfer_name_start) != -1):
        #f = zipfile.ZipFile(dir_tmp, mode="r")
        f = tarfile.open(dir_tmp)
        names = f.getnames()
        for name in names:
          f.extract(name, path=des_dir)
    else:
      extract_tar_files(dir_tmp,des_dir)
  return 0

以上这篇python解压TAR文件至指定文件夹的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python画图--输出指定像素点的颜色值方法

如下所示: # -*- coding: utf-8 -*- #------------------------------------------------------------...

Python入门必须知道的11个知识点

Python被誉为全世界高效的编程语言,同时也被称作是“胶水语言”,那它为何能如此受欢迎,下面我们就来说说Python入门学习的必备11个知识点,也就是它为何能够如此受欢迎的原因. Py...

python scipy卷积运算的实现方法

python scipy卷积运算的实现方法

scipy的signal模块经常用于信号处理,卷积、傅里叶变换、各种滤波、差值算法等。 *两个一维信号卷积 >>> import numpy as np >...

11月编程语言排行榜 Python逆袭C#上升到第4

11月编程语言排行榜 Python逆袭C#上升到第4

TIOBE 11 月编程语言排行榜,Python 逆袭C# 曾经有一段时间,脚本语言因其易于编写和易于运行的特性,被预测在未来将发展强大。因此,Perl,Python,PHP 和 Rub...

pybind11在Windows下的使用教程

pybind11在Windows下的使用教程

Pybind11算是目前最方便的Python调用C++的工具了, 介绍一下在vs2019上写Python的扩展的HelloWorld 1. 去下载pybind11  ...