专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » fso删除文件:使用FSO搜索硬盘文件 »正文

fso删除文件:使用FSO搜索硬盘文件

来源: 发布时间:星期四, 2009年2月12日 浏览:81次 评论:0


<%@LANGUAGE=\"VBSCRIPT\" CODEPAGE=\"936\"%>
<%
dim st
st=timer
\'*************************************************************
\'*************搜索硬盘文件类SearchFile *************
\'*************思路方法: *************
\'*************Set search= SearchFile \'声明 *************
\'*************search.Folder=\"F:+E:\"\'传入搜索源*************
\'*************search.keyword=\"汇编\" \'关键词*************
\'*************search.Search \'开始搜索*************
\'*************Set search=Nothing \'结束*************
\'*************************************************************
Class SearchFile
dim Folders \'传入绝对路径,多路径使用+号连接,不能有空格
dim keyword \'传入关键词
dim objFso \'定义全局变量
dim Counter \'定义全局变量搜索结果数目
\'*****************化**************************************
Private Sub Class_Initialize
Set objFso=Server.CreateObject(\"Scripting.FileObject\")
Counter=0 \'化计数器
End Sub
\'************************************************************
Private Sub Class_Terminate
Set objFso=Nothing
End Sub
\'**************公有成员,思路方法***************************
Function Search
Folders=split(Folders,\"+\") \'转化为
keyword=trim(keyword) \'去掉前后空格
keyword=\"\" then
Response.Write(\"<font color=\'red\'>关键字不能为空</font><br/>\")
exit Function
end
\'判断是否包含非法
flag=instr(keyword,\"\") or instr(keyword,\"/\")
flag=flag or instr(keyword,\":\")
flag=flag or instr(keyword,\"|\")
flag=flag or instr(keyword,\"&\")

flag then \'关键字中不能包含/:|&
Response.Write(\"<font color=\'red\'>关键字不能包含/:|&</font><br/>\")
Exit Function \'如果包含有这个则退出
end
\'多路径搜索
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 _disibledevent=>\'系统文件夹不在历遍的列
If strFdName<>\"Config.Msi\" EQV strFdName<>\"RECYCLED\" EQV strFdName<>\"RECYCLER\" EQV strFdName<>\" Volume Information\" Then
SFN=Folder&\"\"&strFdName \'绝对路径
Call GetAllFile(SFN) \'递归
End If
Next
dim strFlName
\'**********历遍文件********
For Each _disibledevent=>\'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= RegExp
objReg.Pattern=CreatePattern(keyword)
objReg.IgnoreCase=True
objReg.Global=True
retVal=objReg.Test(FileName) \'进行搜索测试,如果通过则上色并输出
retVal then
OutPut=objReg.Replace(FileName,\"<font color=\'#FF0000\'>$1</font>\") \'设置关键字显示颜色
\'***************************该部分可以根据需要修改输出************************************
OutPut=\"<a href=\'#\'>\"&OutPut&\"</a><br/>\"
Response.Write(OutPut) \'输出匹配结果
\'*************************************可修改部分结束**************************************
ColorOn=1 \'加入计数器数目

ColorOn=0
end
Set objReg=Nothing
End Function
End Class
\'************************结束类SearchFile**********************
%>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; char=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\">
<input type=\"submit\" name=\"Submit\" value=\"搜索\">
<a href=\"help.htm\" target=\"_blank\">高级搜索帮助</a>
</form>
<%
dim keyword
keyword=Request.Form(\"keyword\")
keyword<>\"\" then
Set search= SearchFile
search.Folders=\"E:Media+F:\"
search.keyword=keyword
search.Search
Set search=Nothing
response.Write(\"<br/>费时:\"&(timer-st)*1000&\"毫秒\")
end

%>
</body>
</html>



1

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: