os.mkdir(path) FileNotFoundError: [WinError 3] The system cannot find the path specified
猫耳君
os.mkdir(path)FileNotFoundError: [WinError 3] The system cannot find the path specified
在使用django的过程中,发现当创建多级文件夹的时候,使用mkdir会出错,此时将mkdir改为makedirs即可。
- 0
点赞
-
踩
- 0
收藏
-
打赏
-
0
评论
08-01
11-23
04-29
02-20
11-24
02-17
12-15
11-06
04-02
12-27
03-13
02-01
04-21
04-29
12-09
06-13
10-16
08-30
“相关推荐”对你有帮助么?
非常没帮助
没帮助
一般
有帮助
非常有帮助
©️2022 CSDN 皮肤主题:1024 设计师:我叫白小胖 返回首页
The system cannot find the path specified: ‘ ‘
I am trying to split my image data set into train test and val. It has already created the train, test and val folders, but its empty as I keep encountering an error. This is the code I am trying to run on jupyter notebook, I have imported the required libraries like os, numoy, shutil, random:
# # Creating Train / Val / Test folders root_dir = 'Desktop/sem_8_project/brain/brain_tumor_dataset/' # data root path classes_dir = ['no', 'yes'] #total labels val_ratio = 0.15 test_ratio = 0.05 for cls in classes_dir: os.makedirs(root_dir +'train/' + cls) os.makedirs(root_dir +'val/' + cls) os.makedirs(root_dir +'test/' + cls) for cls in classes_dir: src = root_dir + cls # Folder to copy images from allFileNames = os.listdir(src) np.random.shuffle(allFileNames) train_FileNames, val_FileNames, test_FileNames = np.split(np.array(allFileNames),
and this is the error it shows:
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-34-e2cee9006649> in <module> 3 src = root_dir + cls # Folder to copy images from 4 ----> 5 allFileNames = os.listdir(src) 6 np.random.shuffle(allFileNames) 7 train_FileNames, val_FileNames, test_FileNames = np.split(np.array(allFileNames), FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Desktop/sem_8_project/brain/brain_tumor_dataset/no'
Advertisement
Answer
In the last 4 lines of code instead of using: allFileNames = os.listdir(src) I used:
allFileNames = [] for filename in os.listdir(src): img = cv2.imread(os.path.join(src,filename)) if img is not None: allFileNames.append(img)
This worked for me and the directory error got fixed.