1

I am trying to segregate the PDF files from the password protected and normal ones and finally I want to print all details to a log file along with total number of files scanned from the source directory.

I feel code is perfectly till before the last print() statement but the last print() function is not called by the program.

import PyPDF2
import os, sys, datetime
#import shutil

src = 'C:/Users/Balaji.B.R/Downloads/'
dst = 'C:/Users/Balaji.B.R/Downloads/success/'
op = 'C:/Users/Balaji.B.R/Desktop/op.txt'
sys.stdout = open(op,'w')
print("Date & Time :", datetime.datetime.now(), "\n")
files = os.listdir(src)
i=0
for f in files: 
    if (f.endswith('.pdf')):  
        #print("The File Name is",f)
        pdffileobj = open(src+f, 'rb')
        pdfReader = PyPDF2.PdfFileReader(pdffileobj)
        if pdfReader.isEncrypted:
            print("The File Name is",f)
            print("PDF is either protected or corrupted, kindly rescan \n")
            i+=1
            pdffileobj.close()
        else: 
            i+=1
            #shutil.move(src+f,dst+f)
            pdffileobj.close()
    else:
        pass

print("Total PDF files scanned are:", i)
sys.stdout.close()
Joey
  • 1,436
  • 2
  • 19
  • 33

0 Answers0