def zip_dir(zip_name, source_dir,rename_source_dir=False):
src_path = Path(source_dir).expanduser().resolve()<EOL>with ZipFile(zip_name, '<STR_LIT:w>', ZIP_DEFLATED) as zf:<EOL><INDENT>for file in src_path.rglob('<STR_LIT:*>'):<EOL><INDENT>path_in_zip = str(file.relative_to(src_path.parent))<EOL>if rename_source_dir != False:<EOL><INDENT>_,tail = path_in_zip.split(os.sep,<NUM_LIT:1>)<EOL>path_in_zip=os.sep.join([rename_source_dir,tail])<EOL><DEDENT>zf.write(str(file.resolve()), path_in_zip)<EOL><DEDENT><DEDENT>
https://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory