ZipFile内部的ZipFilePython

问题描述

背景

我的主目录中有一个名为delivery_content的目录。在该目录中,有两个文件夹content_123content_456。每个目录都包含一个文本文件。因此,总体结构如下所示。

-delivery_content
 -content_123/
   -content_123.txt
 -content_456/
   -content_456.txt

我正在编写代码,当给定目录时,它将压缩所有内容。

代码

import os
import shutil
from pathlib import Path
from datetime import datetime


DOWNLOAD_DIR = Path(os.getenv("HOME")) / "delivery_content"

date = datetime.today().strftime("%Y-%m-%d")
delivery_name = f"foo_{date}"
shutil.make_archive(str(DOWNLOAD_DIR / delivery_name),"zip",str(DOWNLOAD_DIR))
print("Zipping Has Complete")

因此,对于以上给定的代码,我希望在DOWNLOAD_DIR中看到foo_todays_date.zip,并且当我解压缩它时,我希望看到以下内容

 -content_123/
   -content_123.txt
 -content_456/
   -content_456.txt

但是我看到以下内容

enter image description here

有没有办法避免在zip文件中包含.zip文件?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)