Python 访问窗口目录时出现窗口错误:[Error123]

Python 访问窗口目录时出现窗口错误:[Error123],python,listdir,Python,Listdir,我正在使用以下脚本 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

我正在使用以下脚本

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

Use\\Since\是转义字符<代码>'C:\\Users\\sohan.l\\Desktop\\New folder(3)\\fwdfslabprograms'