gpt4 book ai didi

python-3.x - Shutil.make_archive 未压缩到正确的目的地

转载 作者:行者123 更新时间:2023-12-02 20:24:02 25 4
gpt4 key购买 nike

根据下面的代码,我在使用 python 3 Shutil.make_archive 函数压缩目录时遇到问题。 .testdir 将被压缩,但它被压缩到/home/pi,而不是/home/pi/Backups。

zip_loc = '/home/pi/.testdir'
zip_dest = '/home/pi/Backups/'
shutil.make_archive(zip_loc, 'zip', zip_dest)

谁能解释一下我做错了什么吗?

最佳答案

阅读文档 here我想出了:

zip_loc = '/home/pi/.testdir'
zip_dest = '/home/pi/Backups/'
shutil.make_archive(base_dir=zip_loc, root_dir=zip_loc, format='zip', base_name=zip_dest)

来自文档:

base_name is the name of the file to create, including the path, minus any format-specific extension.

 

root_dir is a directory that will be the root directory of the archive; for example, we typically chdir into root_dir before creating the archive.

 

base_dir is the directory where we start archiving from; i.e. base_dir will be the common prefix of all files and directories in the archive.

 

root_dir and base_dir both default to the current directory.

关于python-3.x - Shutil.make_archive 未压缩到正确的目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46741490/

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