Unable to read path using os.listdir

Viewed 177

I am a beginner and newly join this forum. I have tried many times to read a list of image dataset into my code using os.listdir.

I use code:

img_path = "images/train"
for image in os.listdir(img_path):
    print(image)

Unfortunately, error occured: FileNotFoundError: [WinError 3] The system cannot find the path specified: 'images/testing'

Does it have any issue with Windows? I have tried to add path in the Environment Variable but the same error occurred. Please anyone expert can advise me on how to overcome this issue? Thank you.

2 Answers

You have to give the complete path (Absolute path) of your images folder.

Example: C:/Users/User/images/train

Give the absolute path:

import os
img_path = os.path.abspath("train")
for image in os.listdir(img_path):
    print(image)

Related