123 Eng

Engineering the engineers™

Latest Jobs   Forum Map



Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)


   Computer Science / IT






   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs



Terms of use

Displaying  Source Code(s)  

Search Function


Description : 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.

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)
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


Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG