python - 如何使用 python 归档多个文件夹?
问题描述
我正在尝试将 3 个文件夹:名为 World、World_nether、World_the_end 的文件夹压缩为 1 个 zip 文件,我只能将一个文件夹压缩:
import shutil
import zipfile
shutil.make_archive("text", 'zip', "D:\Scripts\MCserver\Server\world ",)
所有文件夹都在同一个位置/目录
D:\Scripts\MCserver\Server\world
D:\Scripts\MCserver\Server\world_nether
D:\Scripts\MCserver\Server\world_the_end
是目录
解决方案
试试下面的代码,它将所需的文件复制到一个单独的目录中,然后压缩该目录:
import shutil
shutil.copyfile("D:\Scripts\MCserver\Server\world", "D:\Scripts\MCserver\Server\ZipFolder\world")
shutil.copyfile("D:\Scripts\MCserver\Server\world_nether", "D:\Scripts\MCserver\Server\ZipFolder\world_nether")
shutil.copyfile("D:\Scripts\MCserver\Server\world_the_end", "D:\Scripts\MCserver\Server\ZipFolder\world_the_end")
shutil.make_archive("text", 'zip', "D:\Scripts\MCserver\Server\ZipFolder")
推荐阅读
- javascript - 从 Gatsby JS 制作 Axios 发布 Req
- java - 如何在运行时更改值颜色?
- javascript - 为什么我们要在没有依赖数组的情况下使用 useEffect?
- random - 从时间戳生成确定性随机数
- javascript - 如果页面嵌入在 iframe 中,如何显示特定的 HTML 元素?
- sql - 根据另一个表检查列条件
- google-cloud-run - 我可以使用 Deployment Manager 部署 Cloud Run 吗?
- html - 如何在单个功能块中多次渲染到同一个模板
- r - How to break a text in a label into two lines
- vba - How to extract PDF document from SAP GUI? (scripting)