I have a directory with many subdirectories, containing files. I want to open the files ending with "root.vrpj" or "root.vprj", in "App_integrations" folder and copy the lines containing the word "table" to another file.
Until now I've managed to visit each file with this code:
for root, dirs, files in os.walk(movedir):
for filename in files:
if filename.endswith(("root.vrpj", "root.vprj")):
The problem is that what I have now are just the names of the files I want to visit and I'm stuck here.
I finally solved it
Find the files
Filter the files:
Write the output
You can try this:
This is a version of Ajax' code that closes the files you open in the loop (and fixes a couple of other minor issues):
however, when you see 8 levels of indentation you need to refactor, e.g.: