Skip to content

Instantly share code, notes, and snippets.

@selwin
Created April 2, 2010 00:48
Show Gist options
  • Save selwin/352593 to your computer and use it in GitHub Desktop.
Save selwin/352593 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
from os.path import join
from PIL import Image
#print os.path.dirname(__file__)
for current_directory, sub_directories, files in os.walk('.'):
#print "Current directory", current_directory
#print "Sub directories", sub_directories
for filename in files:
path = os.path.join(current_directory, filename)
try:
trial_image = Image.open(path)
trial_image.verify()
print path + ' is a valid image file'
except ImportError:
# Under PyPy, it is possible to import PIL. However, the underlying
# _imaging C module isn't available, so an ImportError will be
# raised. Catch and re-raise.
raise
except: # Python Imaging Library doesn't recognize it as an image
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment