python 編寫 release 目錄壓縮指令碼
import zipfile,os,sys,time
def zip_dir():
dirname = “…/src/UI/TDGisUIMain/x64/Release”
local_time = time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))
zipfilename = “TDGIS_” + local_time + “.zip”
filelist = []
if os.path.isfile(dirname):
filelist.append(dirname)
else:
for root, dirs, files in os.walk(dirname):
for name in files:
filelist.append(os.path.join(root, name))
f = zipfile.ZipFile(zipfilename, “w”, zipfile.ZIP_DEFLATED) #ZIP_STORE, zipfile.ZIP_DEFLATED
for tar in filelist:
if (os.path.isfile(tar) and os.path.splitext(tar)[-1] != “.exp”
and os.path.splitext(tar)[-1] != “.iobj”
and os.path.splitext(tar)[-1] != “.ipdb”
and os.path.splitext(tar)[-1] != “.lib”
and os.path.splitext(tar)[-1] != “.pdb”
and os.path.splitext(tar)[-1] != “.log”
and os.path.splitext(tar)[-1] != “.ilk”):
arcname = tar[len(dirname):]
f.write(tar, arcname)
if (False == os.path.isfile(tar)):
arcname = tar[len(dirname):]
f.write(tar, arcname)
f.close()
zip_dir()