gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:19:09 25 4
gpt4 key购买 nike

我正在使用以下脚本

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com