可能具有一定的危害性,请不要用于非法企图,否则后果自负
<%
'**************************代码源自网络***********************
'******************可能具有一定的危害性,请不要用于非法企图,否则后果自负*******************
'**********************修改:Blue2004***********************
'*************Setnewsearch=newSearchFile'声明*************
'*************newsearch.Folder="F:+E:"'传入搜索源*************
'*************newsearch.keyword="汇编"'关键词*************
'*************newsearch.Search'开始搜索*************
'*************Setnewsearch=Nothing'结束*************
'*************************************************************
Server.ScriptTimeOut=99999'程序加载的超时设置
ClassSearchFile
dimFolders'传入绝对路径,多路径使用+号连接,不能有空格
dimkeyword'传入关键词
dimobjFso'定义全局变量
dimCounter'定义全局变量,搜索结果的数目
'*****************初始化**************************************
PrivateSubClass_Initialize
SetobjFso=Server.CreateObject("Scripting.FileSystemObject")
Counter=0'初始化计数器
EndSub
'************************************************************
PrivateSubClass_Terminate
SetobjFso=Nothing
EndSub
'**************公有成员,调用的方法***************************
FunctionSearch
Folders=split(Folders,"+")'转化为数组
keyword=trim(keyword)'去掉前后空格
ifkeyword=""then
Response.Write("<fontcolor='red'>关键字不能为空</font><br/>")
exitFunction
endif
'判断是否包含非法字符
flag=instr(keyword,"")orinstr(keyword,"/")
flag=flagorinstr(keyword,":")
flag=flagorinstr(keyword,"|")
flag=flagorinstr(keyword,"&")
ifflagthen'关键字中不能包含/:|&
Response.Write("<fontcolor='red'>关键字不能包含/:|&</font><br/>")
ExitFunction'如果包含有这个则退出
endif
'多路径搜索
dimi
fori=0toubound(Folders)
CallGetAllFile(Folders(i))'调用循环递归函数
next
Response.Write("共搜索到<fontcolor='red'>"&Counter&"</font>个结果")
EndFunction
'***************历遍文件和文件夹******************************
PrivateFunctionGetAllFile(Folder)
dimobjFd,objFs,objFf
SetobjFd=objFso.GetFolder(Folder)
SetobjFs=objFd.SubFolders
SetobjFf=objFd.Files
'历遍子文件夹
dimstrFdName'声明子文件夹名
'*********历遍子文件夹******
onerrorresumenext
ForEachOneDirInobjFs
strFdName=OneDir.Name
'系统文件夹不在历遍之列
IfstrFdName<>"Config.Msi"EQVstrFdName<>"RECYCLED"EQVstrFdName<>"RECYCLER"EQVstrFdName<>"SystemVolumeInformation"Then
SFN=Folder&""&strFdName'绝对路径
CallGetAllFile(SFN)'调用递归
EndIf
Next
dimstrFlName
'**********历遍文件********
ForEachOneFileInobjFf
strFlName=OneFile.Name
'desktop.ini和folder.htt隐藏的系统文件不在列取范围
IfstrFlName<>"desktop.ini"EQVstrFlName<>"folder.htt"Then
FN=Folder&""&strFlName
Counter=Counter+ColorOn(FN)
EndIf
Next
'***************************
'关闭各对象实例
SetobjFd=Nothing
SetobjFs=Nothing
SetobjFf=Nothing
EndFunction
'*********************生成匹配模式***********************************
PrivateFunctionCreatePattern(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}")'?号匹配
CreatePattern="("&CreatePattern&")+"'整体匹配
EndFunction
'*****