-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileSearcher.py
More file actions
44 lines (35 loc) · 1013 Bytes
/
fileSearcher.py
File metadata and controls
44 lines (35 loc) · 1013 Bytes
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
36
37
38
39
40
41
42
43
44
from fileReader import *
class FileSearcher:
def __init__( self, path ):
self.path = path
self.reader = FileReader()
self.reader.setPath( path )
self.searchTerm = None
self.__resetResults()
def findAll( self, searchFor ):
self.reader.reopen()
self.__resetResults()
self.searchTerm = searchFor
eof = False
while( not eof ):
eof, hasMatch, line, lineNum = self.checkNextLine()
if( hasMatch ):
self.__saveResult( line, lineNum )
return self.results
def checkNextLine( self ):
hasMatch = False
if( self.reader.isOpen() ):
eof, line, lineNum = self.reader.getNextLine()
if( not eof ):
if( line.find( self.searchTerm ) != -1 ):
hasMatch = True
else:
eof = True
line = ''
lineNum = -1
return eof, hasMatch, line, lineNum
def __resetResults( self ):
self.results = []
def __saveResult( self, line, lineNum ):
result = line, lineNum
self.results.append( result );