Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find all files containing a string in python with glob module

import glob
# path of the current directory
path = './'
text_files = glob.glob(path + '**/*.txt',recursive=True)
print(text_files)


for text_file in text_files:
    required_str= 'Python'
    try:
        with open(text_file) as f:
            # read the file as a string
            text_data = f.read()
            # if the string is find
            if(required_str in text_data):
                print(text_file)
    except:
        pass
Comment

PREVIOUS NEXT
Code Example
Python :: only get top 10 python dataframe 
Python :: f string in python 
Python :: split string and convert to int python 
Python :: create an array of n same value python 
Python :: python repeting timer 
Python :: how to find the last item of a list 
Python :: make screen shot of specific part of screen python 
Python :: how to make a program that identifies positives and negatives in python 
Python :: pymongo [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
Python :: how to press enter in selenium python 
Python :: change dataframe value by index 
Python :: what is hashlib in python 
Python :: creating a list in python 
Python :: qrcode.make python 
Python :: get current data with python 
Python :: select multiple columns in pandas dataframe 
Python :: dataframe create 
Python :: print last exceuted query python 
Python :: moving average pandas 
Python :: max float python 
Python :: python bitwise operators 
Python :: python timer decorator 
Python :: matplotlib to pdf 
Python :: how to import turtle in python 
Python :: python validate url 
Python :: list of seaborn color palette 
Python :: # find out of the memory of the python object 
Python :: python make comparison non case sensitive 
Python :: remove first character of string python 
Python :: python epoch to datetime 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =