Searching through more than one file.

Seymore4Head Seymore4Head at Hotmail.invalid
Sun Dec 28 12:27:47 EST 2014


I need to search through a directory of text files for a string.
Here is a short program I made in the past to search through a single
text file for a line of text.

How can I modify the code to search through a directory of files that
have different filenames, but the same extension?

fname = raw_input("Enter file name: ")  #"*.txt"
fh = open(fname)
lst = list()
biglst=[]
for line in fh:
    line=line.rstrip()
    line=line.split()
    biglst+=line
final=[]
for out in biglst:
    if out not in final:
        final.append(out)
final.sort()
print (final)



More information about the Python-list mailing list