<%@LANGUAGE=VBSCRIPT CODEPAGE=936%>
<%
dim st
st=timer()
'*************************************************************
'*************搜索硬盤文件的類SearchFile *************
'*************調用方法: *************
'*************Set newsearch=new SearchFile '聲明*************
'*************newsearch.Folder=F:+E:'傳入搜索源*************
'*************newsearch.keyword=彙編'關鍵詞*************
'*************newsearch.Search '開始搜索*************
'*************Set newsearch=Nothing '結束*************
'*************Copyright(c)醉雨梧桐小站*************
'*************http://btyz.51web.cn/ *************
'*************************************************************
Class SearchFile
dim Folders '傳入絕對路徑,多路徑使用+號連接,不能有空格
dim keyword '傳入關鍵詞
dim objFso '定義全局變量
dim Counter '定義全局變量,搜索結果的數目
'*****************初始化**************************************
Private Sub Class_Initialize
Set objFso=Server.CreateObject(Scripting.FileSystemObject)
Counter=0 '初始化計數器
End Sub
'************************************************************
Private Sub Class_Terminate
Set objFso=Nothing
End Sub
'**************公有成員,調用的方法***************************
Function Search
Folders=split(Folders,+) '轉化為數組
keyword=trim(keyword) '去掉前後空格
if keyword= then
Response.Write(<font color='red'>關鍵字不能為空</font><br/>)
exit Function
end if
'判斷是否包含非法字符
flag=instr(keyword,/) or instr(keyword,/)
flag=flag or instr(keyword,:)
flag=flag or instr(keyword,|)
flag=flag or instr(keyword,&)
if flag then '關鍵字中不能包含//:|&
Response.Write(<font color='red'>關鍵字不能包含//:|&</font><br/>)
Exit Function '如果包含有這個則退出
end if
'多路徑搜索
dim i
for i=0 to ubound(Folders)
Call GetAllFile(Folders(i)) '調用循環遞歸函數
next
Response.Write(共搜索到<font color='red'>&Counter&</font>個結果)
End Function
'***************歷遍文件和文件夾******************************
Private Function GetAllFile(Folder)
dim objFd,objFs,objFf
Set objFd=objFso.GetFolder(Folder)
Set objFs=objFd.SubFolders
Set objFf=objFd.Files
'歷遍子文件夾
dim strFdName '聲明子文件夾名
'*********歷遍子文件夾******
on error resume next
For Each OneDir In objFs
strFdName=OneDir.Name
'系統文件夾不在歷遍之列
If strFdName<>Config.Msi EQV strFdName<>RECYCLED EQV strFdName<>RECYCLER EQV strFdName<>System Volume Information Then