-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_text_search.py
35 lines (30 loc) · 1.02 KB
/
folder_text_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#
## Kevin Postal ###
# This code searches a path and all its subdirectories
# for a string/regular expression then vists the url
#
# 2010
#
from urlparse import urlparse
import fileinput, glob, string, sys, os, re
from os.path import join
buffsize = 5242880 * 10 #50 Megabyte buffer limit (Server was not having max size)
search_string = r'AKIAIUO7JNJMWSC3V2AA' #search string
def search(path):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
file_path = os.path.join(dirpath, filename)
root = "%s" % (file_path)
f = open(file_path, 'r')
reg_check = re.findall(search_string, f.read(buffsize),re.DOTALL)
if ( reg_check ):
site_url = file_path.split("/")[3]
file_list = list(file_path.split("/")[5:])
file_path = '/'.join(file_list)
print root
f.close()
def main(argv=sys.argv):
search( argv[1] )
if __name__ == "__main__":
main()