gpt4 book ai didi

python - 在 Python 中压缩文件的更好方法(使用单个命令压缩整个目录)?

转载 作者:太空狗 更新时间:2023-10-29 20:33:06 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I zip the contents of a folder using python (version 2.5)?

假设我有一个目录:/home/user/files/。这个目录有一堆文件:

/home/user/files/
-- test.py
-- config.py

我想在 python 中使用 ZipFile 压缩这个目录。我需要 loop through the directory and add these files recursively ,或者是否可以传递目录名称并且 ZipFile 类自动添加其下的所有内容?

最后,我想:

/home/user/files.zip (and inside my zip, I dont need to have a /files folder inside the zip:)
-- test.py
-- config.py

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com