Python Full Text Search Script
Wednesday, August 9th, 2006Many times in the past when I have been attempting to figure out how someone else’s code worked (or wasn’t working as was more often the case), I have wanted a way to perform full text searches of all the documents in a directory and its subdirectories. Unfortunately, Windows (being utterly lacking in all things helpful) fails to provide such a search mechanism.
Python to the Rescue!
So I wrote up this small little Python script which will recursively search all the text documents in a directory tree. By text documents I mean anything that isn’t binary, so it will search just about any kind of source code.
The syntax is very simplistic, with only two arguments, one of which is optional.
search.py [directory] searchstring
The search string should be in quotes if it contains anything but alphanumeric characters, and you should, of course, escape quotes in the string.
Example Usage
search.py "Hello World"
search.py include "$unknownvariable"
search.py "<table colspan=\"2\">"
nice. seems quite fast.