⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.asp

📁 遍历文件夹下的所有文件
💻 ASP
📖 第 1 页 / 共 2 页
字号:
<% Option Explicit %>
<% 
'Set the response buffer to true
Response.Buffer = False 

'Dimension global variables
Dim fsoObject			'File system object
Dim fldObject			'Folder object	
Dim sarySearchWord		'Array to hold the words to be searched for
Dim strSearchWords		'Holds the search words
Dim blnIsRoot			'Set to true if we are searching in the root directory
Dim strFileURL			'Holds the path to the file on the site
Dim strServerPath		'Holds the server path to this script
Dim intNumFilesShown		'Holds the number of files shown so far
Dim intTotalFilesSearched	'Holds the number of files searched
Dim intTotalFilesFound		'Holds the total matching files found
Dim intFileNum			'Holds the file number
Dim intPageLinkLoopCounter	'Loop counter to display links to the other result pages
Dim sarySearchResults(1000,2)	'Two Dimensional Array holding the search results
Dim intDisplayResultsLoopCounter 'loop counter to diplay the results of the search
Dim intResultsArrayPosition	'Stores the array position of the array storing the results
Dim blnSearchResultsFound	'Set to true if search results are found
Dim strFilesTypesToSearch	'Holds the types of files to be searched
Dim strBarredFolders		'Holds the folders that you don't want searched
Dim strBarredFiles		'Holds the names of the files not to be searched
Dim blnEnglishLanguage		'Set to True if the user is using English



' -------------------------- Change the following line to the number of results you wish to have on each page ------------------------------------
Const intRecordsPerPage = 10 'change this to the number of results to show on each page

' --------------------- Place the names of the files types you want searching in the following line sepeararted by commas --------------------------
strFilesTypesToSearch = "htm,html,asp,shtml" 

' --------------------- Place the names of the folders you don't want searched in the following line spearated by commas --------------------------
strBarredFolders = "cgi_bin,_bin" 'cgi_bin and _bin have been put in here as examples, but you can put any folders in here

' ---------- Place the names of the files you don't want searched in the following line spearated by commas include the file extension -------------
strBarredFiles = "adminstation.htm,no_allowed.asp" 'adminstration.htm and not_allowed.asp have been put in as an examples

' -------------------- Set this boolean to False if you are not using an English language web site --------------------------------------------------
blnEnglishLanguage = True 'True = HTML Encode best for English sites \ False = no Emcoding best for non English sites

'-----------------------------------------------------------------------------------------------------------------------------------------------------

'Initalise variables
intTotalFilesSearched = 0

%>
<html>
<head>
<title>麦布站内搜索引擎</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
a {text-decoration: none}
a:active {color: #000000}
a:visited {color: #000000}
a:hover {color: #FF0000}
a:link {color: #000000}
body, table, tr, td {  font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px}
-->
</style>
<script  language="JavaScript">
<!-- Hide from older browsers...

//Preload search icon
var search_icon_off = new Image(); 
search_icon_off.src = "site_search_icon_off.gif";

//Check the form before submitting
function CheckForm () {

	//Check for a word to search
	if (document.frmSiteSearch.search.value==""){
		alert("Please enter at least one keyword to search");
		document.frmSiteSearch.search.focus();
		return false;
	}
	
	return true
}
// -->
</script>
       
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000CC" vlink="#0000CC" alink="#FF0000">
<h2 align="center">麦布站内搜索引擎 Ver 2.0</h2>
<form method="get" name="frmSiteSearch" action="search.asp" onSubmit="return CheckForm();">
  <table cellpadding="0" cellspacing="0" width="553" align="center" height="42">
    <tr> 
   <td height="42" width="143" align="right" rowspan="3" valign="middle">
   <img src="site_search_icon_on.gif" width="58" height="52" align="absmiddle" alt="Search the Web Site" name="searchIcon"> 
   </td>
      <td height="42" width="12" align="right" rowspan="3" valign="middle"> </td>
      <td class="arial" height="14" width="398"> 站内搜索: </td>
    </tr>
    <tr> 
      <td class="normal" height="21" width="398">
      <input type="TEXT" name="search" maxlength="50" size="36" value="<% =Request.QueryString("search") %>">
      <input type="submit" value="搜索" name="submit">
      </td>
    </tr>
    <tr> 
      <td class="normal" height="7" width="398" valign="top"> 搜索选项: 
        <input type="radio" name="mode" value="allwords" CHECKED> 所有文字 
        <input type="radio" name="mode" value="anywords"> 任何文字 
        <input type="radio" name="mode" value="phrase"> 表达式</td>
    </tr>
  </table>
</form>

<%

'Read in all the search words into one variable
strSearchWords = Trim(Request.QueryString("search"))

'If the site is in English then use the server HTML encode method
If blnEnglishLanguage = True Then
	'Replace any HTML tags with the HTML codes for the same characters (stops people entering HTML tags)
	strSearchWords = Server.HTMLEncode(strSearchWords)

'If the site is not english just change the script tags
Else
	'Just replace the script tag <> with HTML encoded &lt; and &gt;
	strSearchWords = Replace(strSearchWords, "<", "&lt;", 1, -1, 1)
	strSearchWords = Replace(strSearchWords, ">", "&gt;", 1, -1, 1)
End If

'Slit each word to be searched up and place in an array
sarySearchWord = Split(Trim(strSearchWords), " ")



'Read the file number to show from
intFileNum = CInt(Request.QueryString("FileNumPosition"))

'Set the number of files shown so far to the file number read in above
intNumFilesShown = intFileNum


'Create the file system object
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")


'If there is no words entered by the user to search for then dont carryout the file search routine
If NOT strSearchWords = "" Then


	'Get the path and the root folder to be searched
	Set fldObject = fsoObject.GetFolder(Server.MapPath("./"))
	
	'Read in the server path to this ASP script
	strServerPath = fldObject.Path & "\"
	
	'Set to true as this is searching the root directory
	blnIsRoot = True
		
	'Call the search sub prcedure
	Call SearchFile(fldObject)			
	
	'Reset server variables
	Set fsoObject = Nothing
	Set fldObject = Nothing	
	
	
	'Call the Bubble Sort procedure to sort the results into highest matches first
	Call SortResultsByNumMatches(sarySearchResults, intTotalFilesFound)
		
	
	'Display the HTML table with the results status of the search or what type of search it is
	Response.Write vbCrLf & "	<table width=""98%"" border=""1"" cellspacing=""0"" cellpadding=""0"" bgcolor=""#CCCCCC"" bordercolor=""#808080"" style=""border-collapse: collapse"" align=""center"">"
	Response.Write vbCrLf & " 	  <tr>"
	
	'Display that there where no matching records found
	If blnSearchResultsFound = False Then 
		Response.Write vbCrLf & " 	    <td>&nbsp;搜索关键字 <b>" & strSearchWords & "</b>. &nbsp;&nbsp;&nbsp;对不起,没有找到任何相关结果!</td>"   
	
	'Else Search went OK so display how many records found
	Else	
		Response.Write vbCrLf & " 	    <td>&nbsp;搜索关键字  <b>" & strSearchWords & "</b>. &nbsp;&nbsp;&nbsp;相关的网页有 " & intFileNum + 1 & " - " & intNumFilesShown & " of " & intTotalFilesFound & ".</td>"	    
	End If
	
	'Close the HTML table with the search status
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"
		
	
	'HTML table to display the search results or an error if there are no results
	Response.Write vbCrLf & "	<table width=""95%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"">"
	Response.Write vbCrLf & "	 <tr>" 
	Response.Write vbCrLf & "	  <td>"   
	
	'If no results are found then display an error message
	If blnSearchResultsFound = False Then 
	
		'Write HTML displaying the error
		Response.Write vbCrLf & "	  <br>"
		Response.Write vbCrLf & "	   您搜索的关键是  - <b>" & strSearchWords & "</b> - 找不到任何与之相匹配的记录. "
	   	Response.Write vbCrLf & "	   <br><br>"
	   	Response.Write vbCrLf & "	   解决方法: "
	   	Response.Write vbCrLf & "	   <br>"
	   	Response.Write vbCrLf & "	   <ul><li>检查下关键字,是否包含有黄色,反动,违反本国现有法律的字词.<li>试试搜索长一点的关键字.<li>试试其他相关的关键字.</ul>"
	
	'Else display the results
	Else
		
		'Loop round to display each result within the search results array
		For intDisplayResultsLoopCounter = (intFileNum + 1) to intNumFilesShown
		
			Response.Write vbCrLf & "	     <br>"
			Response.Write vbCrLf & "	    " & sarySearchResults(intDisplayResultsLoopCounter,1)
			Response.Write vbCrLf & "	     <br>"
		Next
	End If
	
	'Close the HTML table displaying the results
	Response.Write vbCrLf & "	    </td>"
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"

End If

 
'Display an HTML table with links to the other search results
If intTotalFilesFound > intRecordsPerPage then

	'Display an HTML table with links to the other search results
	Response.Write vbCrLf & "	<br>"
	Response.Write vbCrLf & "	<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" align=""center"">"
	Response.Write vbCrLf & " 	  <tr>"
	Response.Write vbCrLf & " 	    <td>"
	Response.Write vbCrLf & "		<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"
	Response.Write vbCrLf & "		  <tr>"
	Response.Write vbCrLf & "		    <td width=""50%"" align=""center"">"
	
	Response.Write vbCrLf & "		Results Page:&nbsp;&nbsp;"
	
		
	'If the page number is higher than page 1 then display a back link    	
	If intNumFilesShown > intRecordsPerPage Then 
		Response.Write vbCrLf & "		 <a href=""search.asp?FileNumPosition=" &  intFileNum - intRecordsPerPage  & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">&lt;&lt;&nbsp;Prev</a> "   	     	
	End If     	
	
	
	'If there are more pages to display then display links to all the search results pages
	If intTotalFilesFound > intRecordsPerPage Then 
		
		'Loop to diplay a hyper-link to each page in the search results    	
		For intPageLinkLoopCounter = 1 to CInt((intTotalFilesFound / intRecordsPerPage) + 0.5)
			
			'If the page to be linked to is the page displayed then don't make it a hyper-link
			If intFileNum = (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage Then
				Response.Write vbCrLf & "		     " & intPageLinkLoopCounter
			Else
			
				Response.Write vbCrLf & "		     &nbsp;<a href=""search.asp?FileNumPosition=" &  (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">" & intPageLinkLoopCounter & "</a>&nbsp; "			
			End If
		Next
	End If
	
	
	'If it is Not the last of the search results than display a next link     	
	If intTotalFilesFound > intNumFilesShown then   	
		Response.Write vbCrLf & "		&nbsp;<a href=""search.asp?FileNumPosition=" &  intNumFilesShown  & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">Next&nbsp;&gt;&gt;</a>"	   	
	End If      	
	
	
	'Finsh HTML the table      	
	Response.Write vbCrLf & "		    </td>"      	
	Response.Write vbCrLf & "		  </tr>"
	Response.Write vbCrLf & "		</table>"		
	Response.Write vbCrLf & "	    </td>"
	Response.Write vbCrLf & "	  </tr>"
	Response.Write vbCrLf & "	</table>"
End If 
%>
  <div align="center">
    <center>  
  <table width="98%" border="1" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC" bordercolor="#808080" style="border-collapse: collapse">
    <tr> 
       <td width="100%" height="18">
        <p align="right"><%Response.Write("Powered By - <a href=""http://www.mybu.net"" target=""_blank"">麦布工作室</a>")%>&nbsp;&nbsp;
       </td>
      </tr>
    </table>
    </center>
  </div>
 <script langauge="JavaScript">document.searchIcon.src = search_icon_off.src</script>
</div>
</body>
</html>
<%



'Sub procedure to do the search
Public Sub SearchFile(fldObject)

	'Dimension local variabales
	Dim objRegExp				'Regular Expersions object
	Dim objMatches				'Holds the matches collection of the regular expresions object
	Dim filObject				'File object
	Dim tsObject				'Text stream object
	Dim subFldObject			'Sub folder object
	Dim strFileContents			'Holds the contents of the file being searched	
	Dim strPageTitle			'Holds the title of the page
	Dim strPageDescription			'Holds the description of the page
	Dim strPageKeywords			'Holds the keywords of the page
	Dim intSearchLoopCounter		'Loop counter to search all the words in the array
	Dim intNumMatches			'Holds the number of matches
	Dim blnSearchFound			'Set to true if the search words are found	
	
	'Error handler
	On Error Resume Next
	
	'Set the error object to 0
	Err.Number = 0
		  		
	'Create the regular expresions object
	Set objRegExp = New RegExp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -