简体   繁体   English

Python - os.rename() - OSError: [WinError 123]

[英]Python - os.rename() - OSError: [WinError 123]

path='U:\\rmarshall\Work For Staff\\ROB\\_Downloads Folder\\'
file='file.pdf'
newFileName=time.strftime('%Y-%m-%d_')+row[1]+time.strftime('_%H:%M:%S')+'.pdf'
newFolderLocation='U:\\Company - do not alter\\'

os.rename(path+file,newFolderLocation+newFileName)

When I run I get:当我运行时,我得到:

>>> os.rename(path+file,newFolderLocation+newFileName)

OSError: [WinError 123] The filename, directory name, or volume label syntax is 
incorrect: 'U:/Company - do not alter/2014-01-14_COMPANY NAME_13:55:23.pdf'

Can anyone see the syntax error?谁能看到语法错误?

The colon : is not allowed in Windows file names. Windows 文件名中不允许使用冒号:

See Naming Files, Paths, and Namespaces on MSDN请参阅MSDN 上的命名文件、路径和命名空间

the error is due to the fact that windows doesn not support charcter "" in the names.错误是由于 Windows 不支持名称中的字符“”。 Your shuld modify this by replacing "\\n" with "".您应该通过将“\\n”替换为“”来修改它。

please check your urls file name in (urls.py) name is correct or not because i was get same issue during my python-Django project .请检查 (urls.py) name 中的 urls 文件名是否正确,因为我在 python-Django 项目中遇到了同样的问题。 hope my answers is useful for you .希望我的回答对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM