ファイル システム内の破損した PDF のチェックに取り組んでいます。私が実行しているテストでは、ほぼ 200k の PDF があります。小さな破損ファイルは正しく警告しているように見えますが、破損した 15 MB の大きなファイルに遭遇し、コードが無期限にハングします。Strict を False に設定しようとしましたが、うまくいきませんでした。問題は最初のオープニングのようです。スレッドを実行してタイムアウトを設定するのではなく (過去にほとんど成功しなかった)、別の方法があることを願っています。
import PyPDF2, os
from time import gmtime,strftime
path = raw_input("Enter folder path of PDF files:")
t = open(r'c:\pdf_check\log.txt','w')
count = 1
for dirpath,dnames,fnames in os.walk(path):
for file in fnames:
print count
count = count + 1
if file.endswith(".pdf"):
file = os.path.join(dirpath, file)
try:
PyPDF2.PdfFileReader(file,'rb',warndest="c:\test\warning.txt")
except PyPDF2.utils.PdfReadError:
curdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
t.write(str(curdate) + " " + "-" + " " + file + " " + "-" + " " + "fail" + "\n")
else:
pass
#curdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
#t.write(str(curdate) + " " + "-" + " " + file + " " + "-" + " " + "pass" + "\n")
t.close()