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
谢谢你的帮助,希望我能投你一票
优秀答案推荐
我是一名优秀的程序员,十分优秀!