Playing little with my code snippet could give some ideas how to proceed (but you need not open the files like I did to find the text in them)
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
You did such a good try that I fixed it to work:
import os
step = 3
def write_files(file, indent=0):
for element in os.listdir(file):
if os.path.isdir(element):
print(indent*' '+'*' + element)
write_files(os.path.join(file,element), indent+step)
else:
print(indent*' '+'-' + element)
write_files('.')
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
I noticed after posting that you got the logic little messed up, but you get the right idea how the recursion works. But you have to have basic case first, the files should be printed for the file list and only recurse to the directories. Maybe better to use os.path.walk with for. Then you do not need to reimplement the walk. (If it is not required by others)
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
Nice debugging! Just use os.path.join also at line 6.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852