python - 窗口错误:[Error123] while accessing a window directory

标签 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, 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/

相关文章:

python - 对模型中的多个数据帧求和

python - 如何获取忽略后缀的所有元素组合?

python - 根据位置将文本文件的各个部分存储到多个字典条目中

python - 遍历文件夹树并将 xmp 数据添加到文件夹中的文件,然后移动

Python:如何根据给定文件夹的内容创建名称列表?

python - 通过网状结构在 R 中运行 gensim 时出现 ImportError : cannot import name 'ssl' from 'urllib3. util.ssl

python - 在不同端口上运行 Tornado 和托管应用程序

python-3.x - 在python中调用函数时出现无文件错误

python - 检查 mp3 文件是否在给定目录中

python - 尝试从目录和子目录中查找所有 .txt 文件