如何使用FSO搜索硬盘文件(2)


SFN=Folder&""&strFdName '绝对路径
Call GetAllFile(SFN) '调用递归
End If
Next
dim strFlName
'**********历遍文件********
For Each OneFile In objFf
strFlName=OneFile.Name
'desktop.ini和folder.htt不在列取范围
If strFlName<>"desktop.ini" EQV strFlName<>"folder.htt" Then
FN=Folder&""&strFlName
Counter=Counter+ColorOn(FN)
End If
Next
'***************************
'关闭各对象实例
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}") '?号匹配
CreatePattern="("&CreatePattern&")+" '整体匹配
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) '进行搜索测试,如果通过则上色并输出
if retVal then
OutPut=objReg.Replace(FileName,"<font color='#FF0000'>$1</font>") '设置关键字的显示颜色
'***************************该部分可以根据需要修改输出************************************
OutPut="<a href='#'>"&OutPut&"</a><br/>"
Response.Write(OutPut) '输出匹配的结果
'*************************************可修改部分结束**************************************
ColorOn=1 '加入计数器的数目
else
ColorOn=0
end if
Set objReg=Nothing
End Function
End Class
'************************结束类SearchFile**********************
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>www.csdn.com.cn</title>
</head>

<body>
<form name="form1" method="post" action="<% =Request.ServerVariables("PATH_INFO")%>">
关键词:
<input name="keyword" type="text" id="keyword">

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2963.html