Joe T. Boka
Joe T. Boka

Reputation: 6581

OSError: cannot identify image file I can't get rid off the Thumb.db using Pillow in Python

I have a dictionary with a list of image files as values. My code works but now I run into this issue wit the Thumbs.db hidden files which is now crashing my code.

from PIL import ImageChops
from PIL import Image
import math, operator
import os

path_folders = ('F:/162 pic sets ready/')
d = {}
for dirpath, dirnames, filenames in os.walk(path_folders):
    d[dirpath] = filenames

dict2 = {k: list(map(lambda x: (k+'/'+x ), v)) for k,v in d.items()}

dict3 = {k: list(map(lambda x: Image.open(x), v)) for k,v in dict2.items()} 

OSError: cannot identify image file 'F:/162 pic sets ready/set77/Thumbs.db'

I tried everything I was supposed to do in my windows to get rid off the Thumbs.db but I still get this same error.

Upvotes: 1

Views: 2659

Answers (2)

Sagnik Sarkar
Sagnik Sarkar

Reputation: 1

use this command to delete all the thumbs.db files :) Hope this helps.Worked in my project like charm :) Run this command in command Prompt

del /s /q "c:\thumbs.db"

Upvotes: 0

Kenly
Kenly

Reputation: 26708

because Thumb.db is created automaticaly by windows,You should test files in for loop.

for dirpath, dirnames, filenames in os.walk(path_folders):
    if someCondition:#for example if 'Thumb.db' not in filenames
       d[dirpath] = filenames

Upvotes: 1

Related Questions