我正在使用以下脚本
import os,sys
folder ='C:\Users\sohan.l\Desktop\New folder (3)\fwdfslabprograms'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
但它抛出以下错误,我该如何纠正它?错误:
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:C:\\Users\\sohan.l\\Desktop\\New folder (3)\x0cwdfslabprograms/*.*
最佳答案
在脚本中使用原始字符串
folder = r'C:\Users\sohan.l\Desktop\New folder (3)\fwdfslabprograms'
就目前而言,\f
被读取为 unicode 字符,并被转换为 \x0c
字符。
由于文件夹名称错误,显然找不到特定文件夹并抛出 WindowsError
。
关于python - 窗口错误:[Error123] while accessing a window directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26228873/