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

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

我有一个 dictionarylistimage filesvalues。我的代码有效,但现在我 运行 进入这个问题 Thumbs.db 隐藏文件现在正在崩溃我的代码。

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'

我尝试了我在 windows 中应该做的所有事情来摆脱 Thumbs.db 但我仍然遇到同样的错误。

因为 Thumb.db 是由 windows 自动创建的,您应该在 for 循环中测试文件。

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

使用此命令删除所有 thumbs.db 文件:) 希望这个 helps.Worked 在我的项目中像魅力一样:) 运行 命令提示符中的此命令

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