Created
November 8, 2018 01:06
-
-
Save agentzex/5304fb68abc9deb3c7c2976dbcbacd3d to your computer and use it in GitHub Desktop.
search a string in the contents of all files of a path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
def search_line(line, string_to_search): | |
if re.search(r'\b' + string_to_search + r'\b', line, re.IGNORECASE): | |
return True | |
def search_string(dir_path, string_to_search): | |
files = [f for f in os.listdir(dir_path)] | |
found = [] | |
for f in files: | |
with open(dir_path + os.sep + f, "r") as file: | |
for line in file: | |
if search_line(line, string_to_search): | |
found.append(f) | |
break | |
return found | |
print search_string(r"E:\smali\il\co\android\activities\login", "Logged in") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment