May-03-2019, 12:17 PM
hey!
I have the following part of a code. It basically does lots of things with PDFs in folders. For reasons I needed to add a criteria wheer if a folder has more than 100 PDF it should be left out. The code looks like this:
I have the following part of a code. It basically does lots of things with PDFs in folders. For reasons I needed to add a criteria wheer if a folder has more than 100 PDF it should be left out. The code looks like this:
#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 continue 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 thisMy problem is that I would need the code to go back to the "for folder in subdirs:" part and start checking the next folder but the continue statement returns it to "if pdfstocheck > 100:". This must be a very newbie question and I am sorry for it, I have been thinking about this for a while now. Is there a way for the code to go back to the "for folder in subdirs:" part after the "if" lines finish?