Sumit Jadhav
Sumit Jadhav

Reputation: 11

In python WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\*.*'

for category in CATEGORIES:  # do dogs and cats
    path = os.path.join(DATADIR,category)  # create path to dogs and cats
    for img in os.listdir(path):  # iterate over each image per dogs and cats
        img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  # convert to array
        plt.imshow(img_array, cmap='gray')  # graph it
        plt.show()  # display!

error occurred :

WindowsErrorTraceback (most recent call last)
<ipython-input-4-be2d68025f07> in <module>()
      1 for category in CATEGORIES:  # do dogs and cats
      2     path = os.path.join(DATADIR,category)  # create path to dogs and cats
----> 3     for img in os.listdir(path):  # iterate over each image per dogs and cats
      4         img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  # convert to array
      5         plt.imshow(img_array, cmap='gray')  # graph it

WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\Bening\\*.*'

Upvotes: 1

Views: 1512

Answers (1)

h4z3
h4z3

Reputation: 5459

WindowsError: [Error 3] The system cannot find the path specified: 'F:/Dataset\\Bening\\*.*'

The error literally says the path is wrong.

Let's look more closely:

We have os.listdir(path) with an error caused by 'F:/Dataset\\Bening\\*.*'

Firstly, paths in Python don't use wildcards .. It's an os.listdir, so you pass a directory in there. If you want to use wildcards, try glob.

Secondly, you use wrong separator in your definition of DATADIR - os.path.join uses the system-specific one which is backslash in Windows (double backslash in print because it needs escaping), you use a normal, forward slash. You can put the path with backslashes by putting r just before opening the string (it means the string is raw - backslashes are literal, not an escaping sequence) or by doubling the backslashes manually. r'F:\Dataset' or 'F:\\Dataset

Upvotes: 1

Related Questions