1from os import listdir
2from PIL import Image
3
4for filename in listdir('./'):
5 if filename.endswith('.png'):
6 try:
7 img = Image.open('./'+filename) # open the image file
8 img.verify() # verify that it is, in fact an image
9 except (IOError, SyntaxError) as e:
10 print('Bad file:', filename) # print out the names of corrupt files