Code Snippet
<!--Form to accept the string will be as follows:-->
<FORM METHOD=POST id=form1 action="searchresult.asp" name=form1>
Enter text to search for: <INPUT TYPE=TEXT NAME=TextToSearch><P>
<INPUT TYPE=SUBMIT VALUE="Begin Search!" id=SUBMIT1 name=SUBMIT1>
</FORM>
<!--To search for a string in particular folder, following is the code: (searchresults.asp)-->
Dim strtextToSearch
strtextToSearch = Request("TextToSearch")
Dim fso
Const ForReading = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim FolderToSearch
FolderToSearch = "D:\temp"
if fso.FolderExists(FolderToSearch) then
Dim objFolder
Set objFolder = fso.GetFolder(FolderToSearch)
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
Dim FilesCounter
FilesCounter = 0
For Each objFile in objFolder.Files
Set objTextStream = fso.OpenTextFile(objFile.Path,ForReading)
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strtextToSearch,1) then
Response.Write objFile.Name & "<br>"
FilesCounter = FilesCounter + 1
End If
objTextStream.Close
Next
if FilesCounter = 0 then
Response.Write "Sorry, No matches found."
else
Response.Write "Total files found : " & FilesCounter
end if
Set objTextStream = Nothing
Set objFolder = Nothing
else
Response.Write "Sorry, invalid folder name"
end if
Set fso = Nothing