- <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
- <%
- dim st
- st=timer()
- '*************************************************************
- '*************搜索硬盤文件的類SearchFile *************
- '*************調(diào)用方法: *************
- '*************Set newsearch=new SearchFile '聲明 *************
- '*************newsearch.Folder="F:+E:"'傳入搜索源*************
- '*************newsearch.keyword="匯編" '關(guān)鍵詞*************
- '*************newsearch.Search '開(kāi)始搜索*************
- '*************Set newsearch=Nothing '結(jié)束*************
- '*************Copyright(c)醉雨梧桐小站 *************
- '*************http://btyz.51web.cn/ *************
- '*************************************************************
- Class SearchFile
- dim Folders '傳入絕對(duì)路徑,多路徑使用+號(hào)連接,不能有空格
- dim keyword '傳入關(guān)鍵詞
- dim objFso '定義全局變量
- dim Counter '定義全局變量,搜索結(jié)果的數(shù)目
- '*****************初始化**************************************
- Private Sub Class_Initialize
- Set objFso=Server.CreateObject("Scripting.FileSystemObject")
- Counter=0 '初始化計(jì)數(shù)器
- End Sub
- '************************************************************
- Private Sub Class_Terminate
- Set objFso=Nothing
- End Sub
- '**************公有成員,調(diào)用的方法***************************
- Function Search
- Folders=split(Folders,"+") '轉(zhuǎn)化為數(shù)組
- keyword=trim(keyword) '去掉前后空格
- if keyword="" then
- Response.Write("<font color='red'>關(guān)鍵字不能為空</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 '關(guān)鍵字中不能包含\/:|&
- Response.Write("<font color='red'>關(guān)鍵字不能包含/\:|&</font><br/>")
- Exit Function '如果包含有這個(gè)則退出
- end if
- '多路徑搜索
- dim i
- for i=0 to ubound(Folders)
- Call GetAllFile(Folders(i)) '調(diào)用循環(huán)遞歸函數(shù)
- next
- Response.Write("共搜索到<font color='red'>"&Counter&"</font>個(gè)結(jié)果")
- 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
- '系統(tǒng)文件夾不在歷遍之列
- If strFdName<>"Config.Msi" EQV strFdName<>"RECYCLED" EQV strFdName<>"RECYCLER" EQV strFdName<>"System Volume Information" Then
- SFN=Folder&"\"&strFdName '絕對(duì)路徑
- Call GetAllFile(SFN) '調(diào)用遞歸
- 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
- '***************************
- '關(guān)閉各對(duì)象實(shí)例
- 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,"*","[^\\\/]*") '*號(hào)匹配
- CreatePattern=Replace(CreatePattern,"?","[^\\\/]{1}") '?號(hào)匹配
- CreatePattern="("&CreatePattern&")+" '整體匹配
- End Function
- '**************************搜索并使關(guān)鍵字上色*************************
- Private Function ColorOn(FileName)
- dim objReg
- Set objReg=new RegExp
- objReg.Pattern=CreatePattern(keyword)
- objReg.IgnoreCase=True
- objReg.Global=True
- retVal=objReg.Test(FileName) '進(jìn)行搜索測(cè)試,如果通過(guò)則上色并輸出
- if retVal then
- OutPut=objReg.Replace(FileName,"<font color='#FF0000'>$1</font>") '設(shè)置關(guān)鍵字的顯示顏色
- '***************************該部分可以根據(jù)需要修改輸出************************************
- OutPut="<a href='#'>"&OutPut&"</a><br/>"
- Response.Write(OutPut) '輸出匹配的結(jié)果
- '*************************************可修改部分結(jié)束**************************************
- ColorOn=1 '加入計(jì)數(shù)器的數(shù)目
- else
- ColorOn=0
- end if
- Set objReg=Nothing
- End Function
- End Class
- '************************結(jié)束類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")%>">
- 關(guān)鍵詞:
- <input name="keyword" type="text" id="keyword">
- <input type="submit" name="Submit" value="搜索">
- <a href="help.htm" target="_blank">高級(jí)搜索幫助</a>
- </form>
- <%
- dim keyword
- keyword=Request.Form("keyword")
- if keyword<>"" then
- Set newsearch=new SearchFile
- newsearch.Folders="E:\Media+F:"
- newsearch.keyword=keyword
- newsearch.Search
- Set newsearch=Nothing
- response.Write("<br/>費(fèi)時(shí):"&(timer()-st)*1000&"毫秒")
- end if
- %>
- </body>
- </html>
硬盤文件搜索代碼(ASP類)
2019-11-01 12:56asp代碼網(wǎng) ASP教程
硬盤文件搜索代碼(ASP類)
延伸 · 閱讀
- 2024-12-13大力士"魔山"硬拉舉起282PB固態(tài)硬盤!重達(dá)45
- 2022-03-07詳解linux添加硬盤分區(qū)掛載教程
- 2022-03-02Ubuntu掛載3T硬盤或大于2T磁盤的方法
- 2022-01-17詳解Linux下掛載新硬盤方法
- 2022-01-12C#使用dir命令實(shí)現(xiàn)文件搜索功能示例
- 2022-01-11HDD硬盤在數(shù)據(jù)中心的持續(xù)價(jià)值
- ASP教程
asp 采集實(shí)戰(zhàn)代碼
最近實(shí)在是太流行采集了,本人是不喜歡采集的,但對(duì)采集的原理我卻很有興趣進(jìn)行研究,拿到了網(wǎng)上采集常用函數(shù),對(duì)其進(jìn)行了一番研究,并實(shí)戰(zhàn),結(jié)果...
- ASP教程
asp之基于adodb.stream的文件操作類
asp之基于adodb.stream的文件操作類...
- ASP教程
ASP常用函數(shù):getpy()
ASP常用函數(shù):getpy()...
- ASP教程
ASP.NET 數(shù)據(jù)源
數(shù)據(jù)源 一個(gè) data sourse 控件與數(shù)據(jù)綁定的控件相互作用,并隱藏了復(fù)雜的數(shù)據(jù)的聯(lián)編過(guò)程。這些是提供數(shù)據(jù)給 data bound 控件的工具,并且支持如插入,刪除...
- ASP教程
asp Access數(shù)據(jù)備份,還原,壓縮類代碼
asp Access數(shù)據(jù)備份,還原,壓縮類實(shí)現(xiàn)代碼,大家可以參考下。...
- ASP教程
asp+javascript實(shí)現(xiàn)404頁(yè)的處理轉(zhuǎn)換
asp+javascript實(shí)現(xiàn)404頁(yè)的處理轉(zhuǎn)換...
- ASP教程
JScript中遍歷Request表單參數(shù)集合的方法
這篇文章主要介紹了JScript中遍歷Request表單參數(shù)集合的方法,本文以遍歷Request.QueryString集合為例給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下...
- ASP教程
asp 標(biāo)記字符串中指定字符變色不區(qū)分大小寫
今天遇到這種問(wèn)題,單純的使用replace函數(shù)不行,他會(huì)改變?cè)械淖址拇笮?在網(wǎng)上找到相關(guān)的代碼,自己備份下...