创建临时目录的存档并将其写入临时目录

2024-04-25 09:11:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个临时目录的存档,并在完成后将该存档放在临时目录中。这样,我可以在我的web应用程序中的请求完成后删除整个目录。你知道吗

现在,当这个过程完成时,归档文件中还包含OutputArchive.zip文件。如何将OutputArchive.zip写入temp_dir而不压缩自身?你知道吗

代码

# zip all contents of this
temp_dir = r'E:\webapps\geodata-dev\data\tmpws55et'

# place the OutputArchive.zip in the above directory without zipping itself
shutil.make_archive(os.path.join(temp_dir, 'OutputArchive'), 'zip', temp_dir)

Tags: 文件ofthe代码目录web应用程序过程