Python Full Text Search Script

Wednesday, August 9th, 2006

Many 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. [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 "Hello World" include "$unknownvariable" "<table colspan=\"2\">"

One Response

  1. Ben Bryant - April 17th, 2008 at 6:46 pm

    nice. seems quite fast.