Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from pathlib import Path
- def ReqET(liste, lpath):
- ''' return list of files containing any of words in liste
- and print contents of files in target folder in lpath
- '''
- ldocs = os.listdir(lpath)
- ld = []
- for doc in ldocs:
- next_file = Path(lpath + "/" + doc)
- if next_file.is_file():
- with open(next_file,"r") as f:
- content = f.read()
- contents = content.split()
- print(f'file: {doc},\n {contents}')
- for search_string in liste:
- if search_string in contents:
- ld = ld + doc.split()
- return ld
- liste = ['words','to', 'search', 'for'] # replace with words to find
- lpath = "/path/to/target/folder" # replace with correct path
- print(ReqET(liste,lpath))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement