<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<%
Dim st
St = timer ()
'*************************************** **********************
*************
* Call method :*************
* Set newsearch = new SearchFile *************
* Newsearch. folder = "F: + E:" 'input the search source *************
* Newsearch. keyword = "assembly" * keyword *************
* Newsearch. Search *************
* Set newsearch = Nothing *************
* Copyright (c): zuyu Wutong xiaozhan *************
/*************
'*************************************** **********************
Class SearchFile
Dim Folders 'is used to input an absolute path. Multiple paths are connected using the plus sign and cannot contain spaces.
Dim keyword' incoming keywords
Dim objFso 'defines global variables
Dim Counter 'defines the number of global variables and search results
********************* *****************
Private Sub Class_Initialize
Set objFso = Server. CreateObject ("Scripting. FileSystemObject ")
Counter = 0' initialize Counter
End Sub
'*************************************** *********************
Private Sub Class_Terminate
Set objFso = Nothing
End Sub
* Public members, call method ***************************
Function Search
Folders = split (Folders, "+") 'is converted to an array
Keyword = trim (keyword) 'remove leading and trailing Spaces
If keyword = "" then
Response. Write ("<font color = 'red'> the keyword cannot be blank </font> <br/> ")
Exit Function
End if
'Determine whether it contains invalid characters
Flag = instr (keyword, "\") or instr (keyword ,"/")
Flag = flag or instr (keyword ,":")
Flag = flag or instr (keyword, "| ")
Flag = flag or instr (keyword ,"&")
The if flag then' keyword cannot contain \/: | &
Response. Write ("<font color = 'red'> the keyword cannot contain/\: | & </font> <br/> ")
Exit Function 'exit if this parameter exists.
End if
'Multi-path search
Dim I
For I = 0 to ubound (Folders)
Call GetAllFile (Folders (I) 'Call the cyclic Recursive Function
Next
Response. Write ("<font color = 'red'>" & Counter & "</font> results found ")
End Function
******************* ***********
Private Function GetAllFile (Folder)
Dim objFd, objFs, objFf
Set objFd = objFso. GetFolder (Folder)
Set objFs = objFd. SubFolders
Set objFf = objFd. Files
'Calendar subfolders
Dim strfdname' declares the sub-Folder name
* History sub-folders ******
On error resume next
For Each OneDir In objFs
StrFdName = OneDir. Name
'The system folder is not in the calendar Column
If strFdName <> "Config. Msi" EQV strFdName <> "RECYCLED" EQV strFdName <> "RECYCLER" EQV strFdName <> "System Volume Information" Then
SFN = Folder & "\" & strFdName 'absolute path
Call GetAllFile (SFN) 'Call Recursion
End If
Next
Dim strFlName
********
For Each OneFile In objFf
StrFlName = OneFile. Name
'Desktop. ini and folder. htt are not in the column range.
If strFlName <> "desktop. ini" EQV strFlName <> "folder. htt" Then
FN = Folder & "\" & strFlName
Counter = Counter + ColorOn (FN)
End If
Next
'***************************
'Close object instances
Set objFd = Nothing
Set objFs = Nothing
Set objFf = Nothing
End Function
*************** ********************
Private Function CreatePattern (keyword)
CreatePattern = keyword
CreatePattern = Replace (CreatePattern ,".","\.")
CreatePattern = Replace (CreatePattern, "+", "\ + ")
CreatePattern = Replace (CreatePattern ,"(","\(")
CreatePattern = Replace (CreatePattern ,")","\)")
CreatePattern = Replace (CreatePattern ,"[","\[")
CreatePattern = Replace (CreatePattern, "]", "\]")
CreatePattern = Replace (CreatePattern ,"{","\{")
CreatePattern = Replace (CreatePattern ,"}","\}")
CreatePattern = Replace (CreatePattern, "*", "[^ \/] *") '*
CreatePattern = Replace (CreatePattern ,"? "," [^ \/] {1 }")'? Number match
CreatePattern = "(" & CreatePattern & ") +" 'overall match
End Function
******** *****************
Private Function ColorOn (FileName)
Dim objReg
Set objReg = new RegExp
ObjReg. Pattern = CreatePattern (keyword)
ObjReg. IgnoreCase = True
ObjReg. Global = True
RetVal = objReg. Test (FileName) 'to Test the search. If it passes the search, the color is colored and the output is
If retVal then
OutPut = objReg. Replace (FileName, "<font color = '# ff0000'> $1 </font>")' sets the display color of the keyword.
* You can modify the output as needed ***** *******************************
OutPut = "<a href = '#'>" & OutPut & "</a> <br/>"
Response. Write (OutPut) 'outputs matching results
* Partial termination **************************************
ColorOn = 1' Number of counters added
Else
ColorOn = 0
End if
Set objReg = Nothing
End Function
End Class
* End class SearchFile ************ **********
%>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Media search </title>
</Head>
<Body>
<Form name = "form1" method = "post" action = "<% = Request. ServerVariables (" PATH_INFO ") %>">
Keywords:
<Input name = "keyword" type = "text" id = "keyword">
<Input type = "submit" name = "Submit" value = "Search">
<A href = "help.htm" target = "_ blank"> Advanced Search Help </a>
</Form>
<%
Dim keyword
Keyword = Request. Form ("keyword ")
If keyword <> "" then
Set newsearch = new SearchFile
Newsearch. Folders = "E: \ Media + F :"
Newsearch. keyword = keyword
Newsearch. Search
Set newsearch = Nothing
Response. Write ("<br/> time-consuming:" & (timer ()-st) * 1000 & "millisecond ")
End if
%>
</Body>
</Html>