# Python 如何压缩目录为 zip

URL: https://caijiao.org/how-to/python/zip-directory
Source: docs/how-to/python/zip-directory.md
Description: Python 如何压缩目录为 zip：用 shutil.make_archive 快速打包目录。 包含脚本示例、处理提醒和相关 Python、工具内容入口。

## 快速答案

用 shutil.make_archive 快速打包目录。

```py
import shutil
shutil.make_archive('dist', 'zip', 'dist')
```

## 使用要点

- 把输入目录和输出目录放到变量里，批量处理前先打印将要操作的文件列表。
- 跨平台脚本优先使用 `pathlib`，避免手写路径分隔符。

## 相关内容

- [Python 问题](/how-to/python/)
- [Python 教程](/python/)
- [Python 文件处理项目](/python/ch11/project-filetool)
- [正则表达式测试工具](/tool/regex-tester)
- [JSON Formatter](/tool/json-formatter)
