Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

String search from multiple files

import os
text = input("input text : ")
path = input("path : ")
# os.chdir(path)
def getfiles(path):
    f = 0
    os.chdir(path)
    files = os.listdir()
    # print(files)
    for file_name in files:
        abs_path = os.path.abspath(file_name)
        if os.path.isdir(abs_path):
            getfiles(abs_path)
        if os.path.isfile(abs_path):
            f = open(file_name, "r")
            if text in f.read():
                f = 1
                print(text + " found in ")
                final_path = os.path.abspath(file_name)
                print(final_path)
                return True
    if f == 1:
        print(text + " not found! ")
        return False

getfiles(path)
Comment

PREVIOUS NEXT
Code Example
Python :: collections counter sort by value 
Python :: pickling python example 
Python :: how to take out every even number from a list in python 
Python :: python turtle module 
Python :: python call function in class 
Python :: pandas if python 
Python :: bar plot python 
Python :: convert list of lists to numpy array matrix python 
Python :: save image to database using pillow django 
Python :: calculate mean of column pandas 
Python :: keras model save 
Python :: convert a string into a list 
Python :: tqdm command that works both in notebook and lab 
Python :: python datetime floor to hour 
Python :: download unsplash images 
Python :: read api from django 
Python :: manage python environment in jupyterlab 
Python :: xarray get number of lat lon 
Python :: pandas to python datetime 
Python :: pandas pivot to sparse 
Python :: how to read json from python 
Python :: labelimg yolo save format 
Python :: how to sort a list in python 
Python :: how can I corect word spelling by use of nltk? 
Python :: numpy copy a array vertical 
Python :: django create view class 
Python :: pandas dataframe row names 
Python :: confusion matrix with seaborn heatmap 
Python :: ImportError: cannot import name include 
Python :: select random img in python using os.listdir 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =