Sunday, 27 June 2021

How to check all the folder inside files and subfolder inside files have particular string present

  • I have folders and files present
  • I have subfolders and files also
  • I need to search a particular string present also in same file other string not present
  • all the files are in .txt
  • I need to check files which string 20210624 is present inside the file and string 20210625 not in the files
  • My output return the file names
import os
match_str = ['20210624']
not_match_str =  ['20210625']
for root, dirs, files in os.walk(path):
    for name in files:
        if name.endswith((".txt")):
             ## search files with match_str `20210624`  and not_match_str `20210625`



from How to check all the folder inside files and subfolder inside files have particular string present

No comments:

Post a Comment