<HTML>
<link REL="stylesheet" HREF="../IncludeFiles/style.css" TYPE="text/css">
<BODY bgcolor="#FFFFFF" text="#000000"><br>
<span class="LinkCat">
Sökresultat med ordet '<%=Request("SearchText")%>'</span><BR>
<%
Const fsoForReading = 1
Dim strSearchText
strSearchText = Request("SearchText")
'Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/download/"))
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
For Each objFile in objFolder.Files
If Response.IsClientConnected then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strSearchText,1) then
Response.Write "<LI><A HREF=""/" & objFile.Name & _
""">" & objFile.Name & "</A><BR>"
bolFileFound = True
End If
objTextStream.Close
End If
Next
if Not bolFileFound then Response.Write "Inga filer hittades..."
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
Hur ska man skriva i denna kod för att man ska kunna lista filerna i underkatalogerna under 'download' också?
vid namn "Advanced Site Search Engine v1.61" som använder Reg exp samt en enklare sökmotor för de som inte har VBScript 5.0.
Du kan ju alltid kolla i koden där! Koden är väldigt bra strukturerad och kommenterad. Surf-net har förutom detta sökverktyg även en hel del mycket användbara script.
<HTML>
<link REL="stylesheet" HREF="../IncludeFiles/style.css" TYPE="text/css">
<BODY bgcolor="#FFFFFF" text="#000000"><br>
<span class="LinkCat">
Sökresultat med ordet '<%=Request("SearchText")%>'</span><BR>
<%
Const fsoForReading = 1
Dim strSearchText, item
strSearchText = Request("SearchText")
'Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/download/"))
[b]Set SubFolder = objFolder.SubFolders
'## -- börja loopa igenom alla submappar
For Each item in SubFolder
Response.Write item & "<BR>"
Next
'## -- slut på submappar --[/b]
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
For Each objFile in objFolder.Files
If Response.IsClientConnected then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strSearchText,1) then
Response.Write "<LI><A HREF=""/" & objFile.Name & _
""">" & objFile.Name & "</A><BR>"
bolFileFound = True
End If
objTextStream.Close
End If
Next
if Not bolFileFound then Response.Write "Inga filer hittades..."
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
Pace:
Då är det bara att skapa ett nytt folder object som körs på varje underkatalog om man vill söka sig nedåt.
Fast ... det kan ju bli en hel del,om sökvägen "råkar" vara c:\ *ler*
Ironhead:
Då får du jämföra katalognamnet med det sök ord som du har.
Tex:
For Each item in SubFolder
If LCase(strSearchString) = LCase(Left(item,Len(strSearchString)) Then
Response.Write item & "<BR>"
End If
Next
cya,
PatrikB
------------------
*Det tar sig sa han som hade eld i håret*
Är detta en dålig lösning? Den funkar iallafall. Kanske går det att göra på ett bättre sätt?
For Each item in SubFolder
a=Replace(item,"C:\Inetpub\wwwroot\Download\","")
If LCase(strSearchText) = LCase(Left(a,Len(strSearchText))) Then
Response.Write a & "<BR>"
End If
Next
strSearchText=Request.Form("SearchText")
For Each item in SubFolder
NewItem=Replace(item,"C:\Inetpub\wwwroot\adsl\Download\","")
If LCase(instr(NewItem,strSearchText)) Then
Response.Write NewItem
End If
Next