《2022年一个硬盘文件搜索的Asp源码源码精华教程.docx》由会员分享,可在线阅读,更多相关《2022年一个硬盘文件搜索的Asp源码源码精华教程.docx(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、2022年一个硬盘文件搜索的Asp源码源码精华教程<%'*代码源自网络*'*可能具有肯定的危害性,请不要用于非法企图,否则后果自负*'*修改:Blue2022*'*Set newsearch=new SearchFile '声明 *'*newsearch.Folder=F:+E:'传入搜寻源*'*newsearch.keyword=汇编 '关键词*'*newsearch.Search '起先搜寻*'*Set newsearch=Nothing '结束*'*Server.Scri
2、ptTimeOut =99999 '程序加载的超时设置Class SearchFiledim Folders '传入肯定路径,多路径运用+号连接,不能有空格dim keyword '传入关键词dim objFso '定义全局变量dim Counter '定义全局变量,搜寻结果的数目'*初始化*Private Sub Class_Initialize Set objFso=Server.CreateObject(Scripting.FileSystemObject) Counter=0 '初始化计数器 End Sub'*Privat
3、e 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(keyw
4、ord,) 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(Fol
5、ders) 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
6、9;历遍子文件夹 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 SFN=FolderstrFdName
7、39;肯定路径 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=FolderstrFlName Counter=Counter+ColorOn(FN) End If Next '
8、* '关闭各对象实例 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
9、(CreatePattern,),) CreatePattern=Replace(CreatePattern,) CreatePattern=Replace(CreatePattern,) CreatePattern=Replace(CreatePattern,{,{) CreatePattern=Replace(CreatePattern,},}) CreatePattern=Replace(CreatePattern,*,/*) '*号匹配 CreatePattern=Replace(CreatePattern,?,/{1}
10、;) '?号匹配 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 Out
11、Put=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 E
12、nd FunctionEnd Class'*结束类SearchFile*%><html><head><meta http-equiv=Content-Type content=text/html; charset=gb2312><title>Media搜寻</title></head><body><form name=form1 method=post action=<% =Request.ServerVariables(PATH_INFO)%>> 关键词: <inp
13、ut name=keyword type=text id=keyword> <input type=submit name=Submit value=搜寻> <a href=help.htm target=_blank>高级搜寻帮助</a> </form><%dim keywordkeyword=Request.Form(keyword)if keyword<> then Set newsearch=new SearchFile newsearch.Folders=d:web +d:xydownsoft '是肯定路径 '不知道能否跨盘,但统一分区下的其他书目可以比如d:www + d:web newsearch.keyword=keyword newsearch.Search Set newsearch=Nothing response.Write(<br/>费时:(timer()-st)*1000毫秒) end if%></body></html>(出处: