#!/usr/bin/python
# -*- coding:utf-8 -*-

import os
import zipfile

def zipdir(sDir, zipName):
    zipf=zipfile.ZipFile(zipName,'w',zipfile.ZIP_DEFLATED)
    basedir=os.path.dirname(os.path.abspath(sDir))
    olddir = os.getcwd()
    os.chdir(basedir)
    (head,tgtdirname)=os.path.split(sDir)
    files=os.walk(tgtdirname)
    for dataset in files:
        for onefile in dataset[2]:
            targetFile=os.path.join(dataset[0],onefile)
            try:
                zipf.write(targetFile,targetFile)
            except:
                print("ERROR: writing file="+targetFile)
    zipf.close()
    os.chdir(olddir)
