def zip_a_folder(src, dst):
if os.path.exists(dst):<EOL><INDENT>print("<STR_LIT>" % dst)<EOL>return<EOL><DEDENT>src, dst = os.path.abspath(src), os.path.abspath(dst)<EOL>cwd = os.getcwd()<EOL>todo = list()<EOL>dirname, basename = os.path.split(src)<EOL>os.chdir(dirname)<EOL>for dirname, _, fnamelist in os.walk(basename):<EOL><INDENT>for fname in fnamelist:<EOL><INDENT>newname = os.path.join(dirname, fname)<EOL>todo.append(newname)<EOL><DEDENT><DEDENT>with ZipFile(dst, "<STR_LIT:w>") as f:<EOL><INDENT>for newname in todo:<EOL><INDENT>f.write(newname)<EOL><DEDENT><DEDENT>os.chdir(cwd)<EOL>
Add a folder and everything inside to zip archive.

Example::

    |---paper
        |--- algorithm.pdf
        |--- images
            |--- 1.jpg

    zip_a_folder("paper", "paper.zip")

    paper.zip
        |---paper
            |--- algorithm.pdf
            |--- images
                |--- 1.jpg

**中文文档**

将整个文件夹添加到压缩包, 包括根目录本身。