我試圖重新命名一個名爲output.txt
與蟒蛇時間戳的文件,但我得到錯誤文件:重命名在python
Traceback (most recent call last):
File "D:/Python27/rename.py", line 10, in <module>
os.rename('output.txt', newfile)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect
我的代碼如下:
import datetime
import os
dt = str(datetime.datetime.now())
newtime = ".".join(dt[0:19].split())
newfile = 'output'+newtime+'.txt'
os.rename('output.txt', newfile)
冒號(:)不允許在Windows中的文件名。 –