日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 压缩文件(1)

發布時間:2025/5/22 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 压缩文件(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先這里是最簡單的將文件壓縮成壓縮文件:

# ?-*-?coding:utf-8?-*-
#
=============================================================================================================
#
#
???brief???:????制作viruswall?的離線升級數據
#
#
???author??:????hechangmin
#
#
???date????:????2008.6?
#
#
=============================================================================================================

import ?os
import ?threading,?zipfile

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)
????
print ?files
????
for ?file? in ?files:
????????background?
= ?AsyncZip(file,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 " )
????


顯然這里壓縮成功了,但是壓縮采用的是zip算法。
還希望是采用 tar+ GZIP 的方式。。。。。

轉載于:https://www.cnblogs.com/soft115/archive/2011/08/10/2134092.html

總結

以上是生活随笔為你收集整理的python 压缩文件(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。