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设计】。

相关文章

Python3使用pandas模块读写excel操作示例

本文实例讲述了Python3使用pandas模块读写excel操作。分享给大家供大家参考,具体如下: 前言 Python Data Analysis Library 或 pandas 是...

Python计时相关操作详解【time,datetime】

本文实例讲述了Python计时相关操作。分享给大家供大家参考,具体如下: 内容目录: 1. 时间戳 2. 当前时间 3. 时间差 4. python中时间日期格式化符号 5. 例子 一、...

Python实现简单的多任务mysql转xml的方法

本文实例讲述了Python实现简单的多任务mysql转xml的方法。分享给大家供大家参考,具体如下: 为了需求导出的格式尽量和navicat导出的xml一致。 用的gevent,文件i/...

使用tensorflow实现线性svm

本文实例为大家分享了tensorflow实现线性svm的具体代码,供大家参考,具体内容如下 简单方法: import tensorflow as tf import numpy a...

解决Python pandas plot输出图形中显示中文乱码问题

解决方式一: import matplotlib #1. 获取matplotlibrc文件所在路径 matplotlib.matplotlib_fname() #Out[3]: u'...