Created
August 14, 2017 22:51
-
-
Save trafficinc/fa8a130cc9f8204e88710fad9ed836a9 to your computer and use it in GitHub Desktop.
Python script to find any text in Files - Recursive
This file contains hidden or 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
#!/usr/bin/python3 | |
import os,sys | |
keyWord = sys.argv[1]; | |
rootdir=('/var/www/mysite/public') | |
found = [] | |
for folder, dirs, files in os.walk(rootdir): | |
for file in files: | |
#if file.endswith('.php'): | |
try: | |
fullpath = os.path.join(folder, file) | |
with open(fullpath, 'r') as f: | |
for line in f: | |
if keyWord in line: | |
print(fullpath) | |
found.extend('1') | |
break | |
except IOError: | |
pass | |
if (len(found) > 0): | |
print(len(found), " file(s)") | |
else: | |
print("There are no matches") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment