May-18-2020, 12:25 PM
This works for me
# /usr/bin/env python3 import os for root, dirs, files in os.walk('./', topdown=True): for name in files: if 'txt' in name: with open(name, 'r') as lines: for line in lines: for word in line.split(): if '|D100|' in word: print(line)
Output:this is some text with |D100|
text with |D100|
still more |D100|
one more text with |D100|
Directory structureOutput:├── another.txt
├── my.txt
└── walk.py
Contents of my.txt
this is some text with |D100|
this text does not have it
more text
text with |D100|
Contents of another.txt
This is another file text
More here
still more |D100|
one more text with |D100|
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags