【发布时间】:2017-03-18 09:50:05
【问题描述】:
import time, os
timestamp = time.strftime('%d.%m_%H:%M')
while True:
print("Beginning checkup")
print("=================")
for fname in os.listdir("C:/SOURCE"):
if fname.endswith(".txt"):
print("found " + fname)
os.rename(fname, fname.replace(fname, timestamp + ".txt"))
time.sleep(5)
这是我的代码。它应该做的是在 SOURCE 中查找 .txt 文件并在名称中添加时间戳。这不知何故给了我一个“FileNotFoundError”。有人有想法吗?
【问题讨论】:
-
Windows 文件名中不能有冒号
:。
标签: python automation