[Tutor] "return" and recursive functions
Jon Cosby
jcosby@wolfenet.com
Sun, 13 Jun 1999 08:07:27 -0700
Problem: I need the following code to return search results for the given
directory and it's sub-directories. As it is, it's returning "hits" only for
the root directory. Any ideas as to how to work around this?
Jon Cosby
def getFile(text, dir):
hits = []
dl = os.listdir(dir)
text = string.lower(text)
for d in dl:
d = dir + '\\' + d
if os.path.isfile(d):
hits.extend(searchtext(text, d)) # Search file for word
elif os.path.isdir(d):
getFile(text, d) # Do sub-directories
return hits