gpt4 book ai didi

python - 使用shutil.make_archive压缩文件时出现意外文件

转载 作者:行者123 更新时间:2023-12-01 09:28:25 28 4
gpt4 key购买 nike

我正在尝试使用shutil.make_archive来压缩文件。

当我使用时:

import shutil
shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test')

我在zip_file中得到了一个zip_file,并且zip_file中的zip_file似乎是一个损坏的文件。有谁知道怎么处理吗?

但是,当我使用时:

make_archive(
'zipfile_name',
'zip', # the archive format - or tar, bztar, gztar
root_dir=file_dir, # root for archive - current working dir if None
base_dir=file_dir) # start archiving from here - cwd if None too

除了文件夹目录错误之外,一切都正确。例如,如果 file_dir = 'C:\Users\aaa\Desktop\test\bbb'zip 文件的结构为:

 Users  
aaa
Desktop
test
bbb

我希望它只能是 bbb/。

有什么想法吗?我非常感谢您的帮助。

最佳答案

我认为解决方案是在不同的目录中创建 zip 文件。从那里开始,类似

shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test', "bbb")

应该为您提供 bbb 目录的存档。

关于python - 使用shutil.make_archive压缩文件时出现意外文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50156657/

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