< %@LANGUAGE="VBSCRIPT " CODEPAGE="936"%>
<%
dim st
st=timer()
'************************************************ ************
'*************Class SearchFile for searching hard disk files *************
'******************Calling method: *************
'*************Set newsearch=new SearchFile 'Statement******************
'******************newsearch.Folder="F:+E:"'Incoming search source******************
'******************newsearch.keyword="Compilation" 'Keyword******************
'************newsearch.Search 'Start searching for******************
'******************Set newsearch=Nothing 'End****************
'************************************************ ************
Class SearchFile
dim Folders 'Pass in the absolute path, use the + sign to connect multiple paths, and there must be no spaces.
dim keyword 'Input keywords
dim objFso 'Define global variables
dim Counter 'Define global variables, the number of search results
'*****************initialization******************************* *******
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 member, calling method****************************
Function Search
Folders=split(Folders,"+") 'Convert to array
keyword=trim(keyword) 'Remove leading and trailing spaces
if keyword="" then
Response.Write("<font color='red'>Keywords cannot be empty</font><br/>")
exit Function
end if
'Determine whether it contains illegal characters
flag=instr(keyword,"") or instr(keyword,"/")
flag=flag or instr(keyword,":")
flag=flag or instr(keyword,"|")
flag=flag or instr(keyword,"&")
if flag then 'Keywords cannot contain /:|&
Response.Write("<font color='red'>Keywords cannot contain /:|&</font><br/>")
Exit Function 'Exit if this is included
end if
'Multiple path search
dimi
for i=0 to ubound(Folders)
Call GetAllFile(Folders(i)) 'Call the loop recursive function
next
Response.Write("A total of <font color='red'>"&Counter&"</font> results were found")
End Function
'******************Traverse files and folders**************************** **
Private Function GetAllFile(Folder)
dim objFd,objFs,objFf
Set objFd=objFso.GetFolder(Folder)
Set objFs=objFd.SubFolders
Set objFf=objFd.Files
'Traverse subfolders
dim strFdName 'Declare subfolder name
'************Traverse subfolders******
on error resume next
For Each OneDir In objFs
strFdName=OneDir.Name
'System folders are not traversed
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
'**********Traverse the files**********
For Each OneFile In objFf
strFlName=OneFile.Name
'desktop.ini and folder.htt are not included in the list
If strFlName<>"desktop.ini" EQV strFlName<>"folder.htt" Then
FN=Folder&""&strFlName
Counter=Counter+ColorOn(FN)
End If
Next
'******************************
'Close each object instance
Set objFd=Nothing
Set objFs=Nothing
Set objFf=Nothing
End Function
'************************Generate matching pattern****************************** **********
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,"*","[^\/]*") '* match
CreatePattern=Replace(CreatePattern,"?","[^\/]{1}") '? match
CreatePattern="("&CreatePattern&")+" 'Overall match
End Function
'******************************Search and color keywords****************** *********
Private Function ColorOn(FileName)
dim objReg
Set objReg=new RegExp
objReg.Pattern=CreatePattern(keyword)
objReg.IgnoreCase=True
objReg.Global=True
retVal=objReg.Test(FileName) 'Perform search test, color and output if passed
if retVal then
OutPut=objReg.Replace(FileName,"<font color='#FF0000'>$1</font>") 'Set the display color of keywords
'******************************This part can be modified as needed and the output*************** *********************
OutPut="<a href='#'>"&OutPut&"</a><br/>"
Response.Write(OutPut) 'Output matching results
'************************************End of the modifiable part******** ******************************
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>www.knowsky.com</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&"ms")
end if
%>
</body>
</html>