Windows でタイムスタンプをファイルの先頭に追加するために取り組んでいるコードがいくつかありますが、正しく動作させることができません。
for root, dirs, files in os.walk('D:\\development\\test'):
for f in files:
fullpath = os.path.join(root + os.sep, f)
print fullpath
if fullpath.endswith('txt'):
d = str(mod_date(fullpath))
dt = d.split()
newName = str(dt[1]) + '_' + f
newNameFull = os.path.join(root + os.sep, newName)
print newNameFull
os.rename(fullpath, newNameFull)
これは正しく印刷されます:
fullpath D:\development\test\New Text Document (2).txt
newNameFull D:\development\test\11:44:04.464341_New Text Document (2).txt
しかし、os.rename は windowsError を返します:
Traceback (most recent call last):
File "D:/Python27/Scripts/getTime.py", line 17, in <module>
os.rename(fullpath, newNameFull)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect
何か案は?// / \ を何度も繰り返してみましたが、正しいものが見つかりません。