gpt4 book ai didi

os.scandir throws mysterious NotADirectory error(Os.scandir抛出神秘的NotA目录错误)

转载 作者:bug小助手 更新时间:2023-10-25 12:25:59 27 4
gpt4 key购买 nike



while I was writing a function loop through a folder

当我在文件夹中编写函数循环时


code here:

代码如下:


import os
from pathlib import Path


path = Path(r'D:\full')
for i in os.scandir(path):#folders
for j in os.scandir(i.path):#subdict
for k in os.scandir(j.path):#files
print(k.path)

it seems to stop whilst a specific folder, a specific file
one that seems to be called 12.288.csv
the full error is here:

当一个特定的文件夹、一个似乎名为12.288.csv的特定文件出现完整错误时,它似乎会停止:


Traceback (most recent call last):
File "D:\project\MOTOR.py", line 7, in <module>
for k in os.scandir(j.path):#files
NotADirectoryError: [WinError 267] The directory name is invalid: 'D:\\full\\normal\\12.288.csv'

interestingly though, the directory does exist, what is wrong?

有趣的是,这个目录确实存在,有什么问题吗?


Alright, I already tried

好的,我已经试过了


\-double slashes
\-raw string
\-checking if directory exists
\-forward slashing and backward slashing

更多回答

D:\\full\\normal\\12.288.csv is a FILE, not a DIRECTORY. You can't call scandir() on a file.

D:\\FULL\\Normal\\12.288.csv是文件,不是目录。不能对文件调用scandir()。

Thanks that helped, wish I could up vote you

谢谢你的帮助,希望我能投你一票

优秀答案推荐
更多回答

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