如何在python中使用shutil.make_archive()创建没有文件扩展名的zip存档?

2024-09-28 05:17:40 发布

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

我需要创建一个自定义扩展名为“.stz”的zip存档,因为这是应用程序将在其中使用的唯一可接受的文件格式。使用shutil.make_存档,即使我没有指定扩展名,文件也始终具有.zip文件扩展名。目前正在创建后重命名它。有更好的方法吗

import os
import shutil

output = “file.stz”
dir_name = “files/“
zip_name = shutil.make_archive(‘tmp’, ‘zip’, dir_name)
os.rename(zip_name, output)

Tags: 文件方法nameimport应用程序outputmakeos

热门问题