This is the code to clear the damaged image .
Call the main program ,path
Parameter specifies the folder path .
import imghdr
import os
def main(root):
path_list = os.listdir(root)
items = {
"bed": 0, "bed_list": []}
def is_verify(path):
if imghdr.what(path):
print('Good img',path)
else:
items["bed"] += 1
items["bed_list"].append(path)
os.remove(path)
for path in path_list:
is_verify(root + '/' + path)
print(f' Delete damaged files in total {
items["bed"]} individual .')
print(" The damaged files are as follows :", "\n".join(items['bed_list']))
if __name__ == '__main__':
main("path")