---
title: "Fso sökfunktion"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/38094-fso-sökfunktion"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Vide"
published: "2000-07-11T07:09:00.000Z"
updated: "2000-07-11T07:09:00.000Z"
replies: 0
views: 1100
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/38094-fso-sökfunktion"
---

# Fso sökfunktion

## #1 — Vide, 2000-07-11T07:09Z

Detta är ett skript som söker igenom en mapp efter söksträngen ifrån sida 1. Som det är inställt nu så letar den igenom wwwroot, Set objFolder = objFSO.GetFolder(Server.MapPath("/"))
 du kan ändra detta till en vilken mapp du vill.

Skriptet finnes på <http://www.4guysfromrolla.com> 

Search.asp

```
<HTML>
<BODY>
<FORM METHOD=POST ACTION="TextSearch.asp">
  Enter text to search for:
  <INPUT TYPE=TEXT NAME=SearchText>
  <P>
  <INPUT TYPE=SUBMIT VALUE="Begin Search!">
</FORM>
</BODY>
</HTML>
```

TextSearch.asp 

```
<HTML><BODY>
<B>Search Results for <%=Request("SearchText")%></B><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("/"))

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 "No matches found..."

Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</BODY></HTML>
```

Permalänk: https://www.webforum.nu/p/38094

---

Tråden på webben: https://www.webforum.nu/amne/asp/38094-fso-sökfunktion
