Python tar、zip压缩文件操作方法,pythontar,python语言源码练习
Python tar、zip压缩文件操作方法,pythontar,python语言源码练习
python语言源码练习,tar、zip压缩文件操作方法参考示例。
import osimport threading, zipfileimport 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)#www.iplaypy.com 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 " )
编橙之家文章,
相关内容
- Python调用摄像头摄像并保存图片的方法源码,,用pytho
- Python 类快速排序方法找到第定n小数的方法,python小数
- Python实现SYSLOG服务器与MYSQL数据库写入源码,pythonsysl
- python方法判断IP的合法性源码分享,python合法性,用pyt
- Python代码音乐mp3下载器源码分享,python下载器,用pytho
- python方法实现磁盘剩余空间查询操作,python磁盘,想知道
- python转换工具之汉语拼音与国际音标的实现,python转换
- Python方法完成自动合并文本文件操作,python文本文件
- Python math方法算24点代码详解,pythonmath,计算24点的方法
- 如何让Cookie.py模块用冒号做key,cookie.py冒号,python的Co
评论关闭