else/Toolbox/fileswith.py
Ethan Dalool b0187f3269 else
2016-11-17 22:24:52 -08:00

27 lines
No EOL
748 B
Python

import fnmatch
import glob
import re
import sys
sys.path.append('C:\\git\\else\\spinaltap'); import spinal
filepattern = sys.argv[1]
searchpattern = sys.argv[2]
for filename in spinal.walk_generator():
filename = filename.absolute_path
if not fnmatch.fnmatch(filename, filepattern):
continue
matches = []
handle = open(filename, 'r', encoding='utf-8')
try:
with handle:
for (index, line) in enumerate(handle):
if re.search(searchpattern, line, flags=re.IGNORECASE):
line = '%d | %s' % (index, line.strip())
matches.append(line)
except:
pass
if matches:
print(filename)
print('\n'.join(matches))
print()