I am a new learner in python and got stuck while working with For Loop. I am trying to get the Document information of some pdf files and write down the Information in a text file. During Execution it shows all the file names in the output window, but writes only single file data if I want to write it in a text file.
import PyPDF2
import os
d = "C:\\New folder"
for filename in os.listdir(d):
a = PyPDF2.PdfFileReader(d + "\\" + filename, strict= False)
c = a.getDocumentInfo()
g = filename + " : " + str(c)
print(g)
with open("check.txt", "w") as f:
f.writelines(g + "\n")