forked from wangandi520/andyspythonscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
检测图片损坏(拖拽,多个文件或文件夹).py
39 lines (32 loc) · 943 Bytes
/
检测图片损坏(拖拽,多个文件或文件夹).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# encoding:utf-8
# https://github.com/wangandi520/andyspythonscript
# pip install pillow
from PIL import Image
from pathlib import Path
import sys
def doVerify(filePath):
# typeof(filePath): Path
# 设置文件类型
fileType = ['.png','.jpg','.jpeg','.bmp','.webp']
if filePath.suffix.lower() in fileType:
try:
Image.open(filePath).verify()
except:
print(filePath.name)
def main(inputPath):
print('只显示可能损坏的文件名:')
del inputPath[0]
for aPath in inputPath:
if Path.is_dir(Path(aPath)):
for file in Path(aPath).glob('**/*'):
doVerify(file)
if Path.is_file(Path(aPath)):
doVerify(Path(aPath))
print('检测结束。')
input()
if __name__ == '__main__':
try:
if len(sys.argv) >= 2:
main(sys.argv)
except IndexError:
pass