We now loop through each file in the array of files created above (for file in files) and use a with clause to process each in memory as a file object (file handle)
It now reads each line in the file, assigning it to ‘line’ and has a series of IF statements searching for text in each line that we want, or combinations. Then prints if it has a match.
After the IF statements, it moves to the next file, then up the chain to the next directory until it has finished! (c variable tracks the directory, we add 1 to it after both loops run so it knows to move to the next dir in the array)
I’ve tested this on files with 100s of directories and 100s of files and it works very well! If you liked this, I wrote a few other automation scripts for web scraping here.