使用Python合併壓縮檔案(jar)
阿新 • • 發佈:2019-01-04
#! /usr/bin/python
import zipfile
import os
import shutil
def commbinJar(originJar, destzip):
zfile = zipfile.ZipFile(originJar)
names_zfile = zfile.namelist()
zfile.extractall()
zfile.close()
for filename in names_zfile:
destzip.write(filename)
for filename in names_zfile:
rootPath = filename.split('/')[0];
if os.path.exists(rootPath):
shutil.rmtree(rootPath)
def commbinJars(jarDir, destzipJarName):
jarlist = os.listdir(jarDir)
dstzip = zipfile.ZipFile(destzipJarName, 'w')
for filename in jarlist:
print filename
if filename.endswith(".jar"):
print filename
commbinJar(filename, dstzip)
dstzip.close()
commbinJars("./", "comm.jar")
os.system('pause')