Last active
February 22, 2021 19:55
-
-
Save gothicx/b63ee1af2228d5168e62f7a863ee9233 to your computer and use it in GitHub Desktop.
Find valid images using Python code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Find and clean up invalid images | |
# | |
# bY Marco Rodrigues 2021 - <[email protected]> | |
# | |
import imghdr | |
from os import walk, path, remove | |
dir_moments = '/volume1/homes/user/Drive/Moments' | |
extensions = ['.jpg', 'jpeg', '.png', '.gif'] | |
exclude_dirs = ['@eaDir'] | |
for root, dirs, files in walk(dir_moments): | |
dirs[:] = [d for d in dirs if d not in exclude_dirs] | |
for fn in files: | |
for ext in extensions: | |
if fn.lower().endswith(ext): | |
filename = root + "/" + fn | |
if imghdr.what(filename) == None: | |
print "Removing file" + filename + "..." | |
remove(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment