【发布时间】:2023-01-25 18:34:01
【问题描述】:
我问过这个问题,并提供了可能的解决方案,但没有一个有效。如果有人能为我提供解决此问题的方法,我将不胜感激。非常感谢你提前。
尝试重命名 ~/Downloads 文件夹中的文件。
这是代码:
import os
from datetime import datetime
# adding date-time to the file name
current_timestamp = datetime.today().strftime('%d-%b-%Y')
old_name = r"/Downloads/Test.xlsx"
new_name = r"/Downloads/Test_" + current_timestamp + ".xlsx"
os.rename(old_name, new_name)
我遇到的错误:
FileNotFoundError: [WinError 3] The system cannot find the path specified: '/Downloads/Test.xlsx' -> '/Downloads/Test_25-Jan-2023.xlsx'
【问题讨论】: