May-07-2019, 10:38 AM
Maybe by this way:
#lots of code before this for folder in subdirs: os.chdir(str(subdirs[subdirnumber + 1])) #opens the subfolder pdflist = glob.glob("**/*.pdf", recursive=True) #lists all the pdfs in the subfolder and its subfolders pdfstocheck = sum(1 for s in pdflist if 'apple' in s or 'orange' in s or 'cherry' in s or 'banana' in s or 'potato' in s or 'pear' in s or 'blackberry' in s or 'peanuts' in s or 'avocados' in s) if pdfstocheck > 100: f.write(str(os.getcwd()) + ',' + 'More than 100 PDFs to check. Please check the 793 reports manually.' + ',' + '\n') print("Now checking the folder: " + str(os.getcwd())) print("Number of PDFs in the folder: " + str(len(pdflist))) print("Number of PDFs to be checked: " + str(pdfstocheck)) print("ERROR: Number of PDFs over 100. Please check the 793 reports manually.") print("") os.chdir(mainworkingdirectory) subdirnumber = subdirnumber + 1 else: print("Now checking the folder: " + str(os.getcwd())) print("Number of PDFs in the folder: " + str(len(pdflist))) print("Number of PDFs to be checked: " + str(pdfstocheck)) for file in pdflist: #Lots of code after this