Search Function:

The Search function recursively searches all files on a hard drive for a specific phrase from a specified start directory. The Search function is not meant for web site searches by site users but was designed to be used in code only to obtain the path of a file matching the given phrase. The Search function returns a string of absolute paths of all files containing the search phrase. Each path is separated by a carriage-return line-feed (vbCrLf) that is used as a delimiter. The Search function has two required arguments, phrase and directory. Phrase is a string representing these exact phrase or word grouping to search. Directory is the absolute path of the folder to begin recursively searching.

string = Search(phrase, directory)
Example Usage:
Search all files of the entire web site for the exact phrase "request.cookies" and delete them (also uses the kill statement).
 ' declare variables
dim a, b, i

 ' search the entire web site for the phrase "request.cookies"
a = Search( "request.cookies", server.mappath("/") )   

 ' iterate the array of results
b = split(a , vbCrLf)
For i = 0 to ubound(b) - 1
	 ' delete each matching page
	Kill b(i)
ASP Source Code:
Private Function Search(byVal phrase, byVal directory)
	Dim objFSO, currentFolder, objFile, currentFile
	Dim strSearch, fileContents, objFolder

	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set currentFolder = objFSO.GetFolder(directory)
	For Each objFile In currentFolder.Files
		If LCase( objFile.Path ) = _
			LCase( server.mappath( _
			request.serverVariables("SCRIPT_NAME") ) ) Then
			Set currentFile = _
				objFSO.OpenTextFile( objFile.Path, 1, False )
			fileContents = lcase( currentFile.ReadAll() )
			Set currentFile = Nothing
			If Instr( fileContents, phrase ) Then
				strSearch = strSearch & objFile.Path & vbCrLf
				strSearch = strSearch & ""
			End If
		End If
	For Each objFolder in currentFolder.SubFolders
		strSearch = strSearch & Search( phrase, objFolder )
	Set currentFolder = Nothing
	Set objFSO = Nothing
	Search = CStr( strSearch )
End Function