Batch check operation pictures

Mainly to check whether the file is damaged

import imghdr
import os
root = 'C:/Python文件夹/知乎图片'
path_list = os.listdir(root)

bed_times = 0
def is_verify(path):
    global bed_times
    if imghdr.what(path):
        print('Good img')
    else:
        bed_times += 1
        os.remove(path)
        print('图片已损坏,删除!')

if __name__=='__main__':
    for path in path_list:
        is_verify(root+'/' + path)
    print(f'总计删除损坏文件{bed_times}个.')

Ideas:

  1. Use the standard library imghdr to check for damage
  2. Use the os library to get the path and delete damaged files in batches

Effect picture:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_17802895/article/details/109583297