Python 压缩文件(2),python压缩文件,加入了tar环节,但是最
Python 压缩文件(2),python压缩文件,加入了tar环节,但是最
加入了tar环节,但是最后还是zip压缩
import os import threading, zipfile import tarfile class AsyncZip(threading.Thread): def __init__ (self, infile, outfile): threading.Thread. __init__ (self) self.infile = infile self.outfile = outfile def run(self): state = ' w ' if os.path.isfile(self.outfile) == True: state = ' a ' f = zipfile.ZipFile(self.outfile, state, zipfile.ZIP_DEFLATED) f.write(self.infile) f.close() print ' Finished background zip of: ' , self.infile def zipDir(src,dst): initPath = os.getcwd() tempDST = os.path.join(os.getcwd(),dst) tempSRC = os.path.join(os.getcwd(),src) os.chdir( tempSRC ) files = os.listdir(os.curdir) tar = tarfile.open( " temp.tar " , " w " ) for file in files: tar.add(file) tar.close() background = AsyncZip( " temp.tar " ,dst) background.start() background.join() # Wait for the background task to finish os.chdir( initPath ) print os.getcwd() # test ok if __name__ == ' __main__ ' : zipDir( " D:\\\\AutoUpdate\\\\DataDist\\\\viruswall\\\\Data\\\\KSVW-VirusDB\\\\ " , " d:\\\\AutoUpdate\\\\DataDist\\\\viruswall\\\\Data\\\\update\\\\KSVW-VirusDB.tgz " )#该片段来自于http://byrx.net
相关内容
- Python 解析xml(dom),python解析xmldom,from xml.dom
- Python中的工厂方法 funtional的思维来做 非oop的实现,f
- Python 自动连接ssh,Python连接ssh,#!/usr/bin/p
- md5Crack_V0.1,,Python语言: md
- python.递归遍历指定的目录,python递归遍指定,Python语言
- 网易新闻小爬虫.v0.1,网易新闻爬虫.v0.1,Python语言: 网易
- Python版的农历日历Calendar,功能简单,pythoncalendar,Pyth
- 人性化的时间(比如:两分钟以前),人性化两分钟
- 筛法生成质数(素数)的生成器,质数素数,Python语言
- 计算n*n网格生成树的数目,网格,Python语言: 计算
评论关闭