ziplib 解压操作

ziplib 解压操作



[Copy to clipboard] [ - ]
CODE:
"""最近在为公司的程序做次升级,中间用到了python做客户端,其间用到了ftplib,ziplib等一些技术
     这些技术也是第一次用到,再此也贴出来,供新手学习,毕竟俺也是Python的新手,等整个程序做完了,再将整个模块贴出来
"""
from zipfile    import *

source_zip="c:\\pbd\\20070118-140549.zip"
target_dir="c:\\pbd\\"
myzip=ZipFile(source_zip)
myfilelist=myzip.namelist()
count_file=len(myfilelist)
i=0

for i in xrange(0,count_file):
    file_path = target_dir+myfilelist[i]

    #make dirs
    if  not os.path.exists(os.path.split(file_path)[0]) :
        os.makedirs(os.path.split(file_path)[0])


    f_handle=open(file_path,"wb")
    f_handle.write(myzip.read(myfilelist[i]))
    f_handle.close()
myzip.close()

感谢分享
貌似有python写的rar文件解压的
以前看到过
import tarfile,os,sys

tar = tarfile.open("sample.tar.gz", "w:gz")

path =os.getcwd()

namelist = ['msg0001.WAV ','msg0002.WAV ','msg0003.WAV ']

for name in namelist:

    tarinfo = tar.gettarinfo(name,name)
    print '\nII',tarinfo.name, "is ==", tarinfo.size, "==bytes in size and is",
    tar.addfile( tarinfo,file(name,'rb'))

tar.close()
小小小小小小的~~~