-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebuging.py
50 lines (38 loc) · 1.18 KB
/
debuging.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
40
41
42
43
44
45
46
47
48
49
50
# -*- encoding: utf-8 -*-
"""
@File : test.py
@Time : 2021/1/11 19:12
@Author : SJY
@Email : [email protected]
@Software: PyCharm
@function: 查找打不开的PDF文件,以及缺失的PDF文件
"""
import os
import tkinter as tk
from tkinter.filedialog import askdirectory
from PyPDF2 import PdfFileReader
class BatchRename:
def __init__(self):
pass
def isValidPDF_pathfile2(self,pathfile):
bValid = True
try:
reader = PdfFileReader(pathfile)
if reader.getNumPages() < 1: # 进一步通过页数判断。
bValid = False
except:
bValid = False
return bValid
def rename(self, dirpath_): # 表示需要命名处理的文件夹
for rootd, dirs, files in os.walk(dirpath_):
if len(files) != 3:
print(rootd,"缺失",3-len(files))
for file in files:
if not self.isValidPDF_pathfile2(os.path.join(rootd,file)):
print(rootd,file)
if __name__ == '__main__':
root = tk.Tk()
root.withdraw()
dirpath = askdirectory(title=u'选择成绩表文件夹')
demo = BatchRename()
demo.rename(dirpath)