import os import cv2 import numpy as np path = "./test_img/" imglist = os.listdir(path) for fi in imglist: img_folder = path+fi print(img_folder) image = cv2.imdecode(np.fromfile(img_folder, dtype=np.uint8), -1) try: image.shape except: print('fail to read',img_folder) os.remove(img_folder) continue