gpt4 book ai didi

python - 在没有 copystat 的情况下使用 shutil.copytree

转载 作者:行者123 更新时间:2023-11-28 17:33:26 28 4
gpt4 key购买 nike

我正在尝试编写一个 python 脚本来备份一个文件夹,并将其保留 x 天。

我用

shutil.copytree(source, finaldest)

我的问题是,原始文件的时间戳仍然存在,这意味着如果其中的文件早于 x 天,文件夹将被删除。我想要的是时间戳作为备份时间,而不考虑原始创建日期

最佳答案

完成copytree()之后,您可以像这样修改文件的时间戳:

import os

for dirpath, _, filenames in os.walk(finaldest):
os.utime(dirpath, None)
for file in filenames:
os.utime(os.path.join(dirpath, file), None)

关于python - 在没有 copystat 的情况下使用 shutil.copytree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720237/

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