Вопрос по python, image, search – Как улучшить поиск с помощью os.walk и fnmatch

4

Error: User Rate Limit Exceededos.walk а такжеfnmatchError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

import fnmatch
import os

images = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
matches = []

for root, dirnames, filenames in os.walk("C:\\"):
    for extension in images:
        for filename in fnmatch.filter(filenames, extension):
            matches.append(os.path.join(root, filename))

Ваш Ответ

3   ответа
4

re

import os
import re

matches = []

img_re = re.compile(r'.+\.(jpg|png|jpeg|tif|tiff)$', re.IGNORECASE)

for root, dirnames, filenames in os.walk(r"C:\windows"):
    matches.extend(os.path.join(root, name) for name in filenames if img_re.match(name))
2

for root, dirnames, filenames in os.walk("C:\\"):
    for extension in extensions:
        matches.extend(os.path.join(root, filename) for filename 
                       in fnmatch.filter(filenames, extension))

isdir /s ...

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
2
import os
extns = ('.jpg', '.jpeg', '.png', '.tif', '.tiff')
matches = []
for root, dirnames, fns in os.walk("C:\\"):
    matches.extend(
        os.path.join(root, fn) for fn in fns if fn.lower().endswith(extns)
        )
Error: User Rate Limit Exceeded

Похожие вопросы