---
title: "Sök med FSO"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/82480-sök-med-fso"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Asa"
published: "2003-07-22T13:56:11.000Z"
updated: "2003-08-01T12:50:14.000Z"
replies: 5
views: 373
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/82480-sök-med-fso"
---

# Sök med FSO

## #1 — Asa, 2003-07-22T13:56Z

Har denna kod som söker efter filnamn i en mapp. Men nu vill jag att den ska söka igenom alla mappar i strMapp oxå.

```
<table width="450" border="0">
<form method="post" action="sok.asp?do=sok">
 <tr>
    <td valign="top">
      Skriv sökord:
      <input type="text" name="searchtext"> &nbsp; <input type="submit" value="starta sökning">
   </td>
 </tr>
</form> 
</table>

<%If Request.QueryString("do") = "sok" Then%>

<b>Sök resultat för: <%=Request("SearchText")%></b><br>

<%Const fsoForReading = 1

strMapp = "MAPPNAMN"

Mappen = Server.MapPath(strMapp)
MappUrl = Mid(Mappen, InStrRev(Mappen, "\") + 1)

strSearchText = Request("SearchText")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Mappen)

bolFileFound = False

For Each objFile in objFolder.Files
  If Response.IsClientConnected then
    If InStr(1,objFile.Name,strSearchText,1) then
       Response.Write "<b>»</b> <a href=" & MappUrl & "/" & objFile.Name & ">" & objFile.Name & "</a><br>"
       bolFileFound = True
    End If
  End If
Next

if Not bolFileFound then Response.Write "Inga sökresultat..."

Set objFolder = Nothing
Set objFSO = Nothing

End If%>
```

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

## #2 — Engine^, 2003-07-22T14:01Z

```
Set objSubFolder = objFolder.SubFolders

For Each objSF In objSubFolder
  [blue].
  .
  .[/blue]
Next
```

Jag tror det blir så... du kan ju kolla lite mer här [Folders Collection](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jscolFolders.asp).

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

## #3 — Asa, 2003-07-22T14:15Z

Ska testa! Tack...

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

## #4 — Asa, 2003-08-01T07:17Z

Så här? Men det funkar ju ej

```
<table width="450" border="0">
<form method="post" action="sok.asp?do=sok">
 <tr>
    <td valign="top">
      Skriv sökord:
      <input type="text" name="searchtext">   <input type="submit" value="starta sökning">
   </td>
 </tr>
</form> 
</table>

<%If Request.QueryString("do") = "sok" Then%>

<b>Sök resultat för: <%=Request("SearchText")%></b><br>

<%Const fsoForReading = 1

strMapp = "MAPPNAMN"

Mappen = Server.MapPath(strMapp)
MappUrl = Mid(Mappen, InStrRev(Mappen, "\") + 1)

strSearchText = Request("SearchText")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Mappen)

bolFileFound = False

For Each objFile in objFolder.Files
  If Response.IsClientConnected then
    If InStr(1,objFile.Name,strSearchText,1) then
       Response.Write "<b>»</b> <a href=" & Mappen & objFile.Name & " target=""_blank"">" & objFile.Name & "</a><br>"
       bolFileFound = True
    End If
  End If
Next
Set objSubFolder = objFolder.SubFolders

For Each objSF In objSubFolder
  If Response.IsClientConnected then
    If InStr(1,objSF.Name,strSearchText,1) then
       Response.Write "<b>»</b> <a href=" & Mappen & "/" & objSF.Name & ">" & objSF.Name & "</a><br>"
       bolFileFound = True
    End If
  End If
Next

if Not bolFileFound then Response.Write "Inga sökresultat..."

Set objFolder = Nothing
Set objFSO = Nothing

End If%>
```

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

## #5 — solbulle, 2003-08-01T09:42Z

Du måste ju "gå in" in mappen och söka för varje mapp som hittas, typ:

```
<table width="450" border="0">
<form method="post" action="sok.asp?do=sok">
 <tr>
    <td valign="top">
      Skriv sökord:
      <input type="text" name="searchtext">   <input type="submit" value="starta sökning">
   </td>
 </tr>
</form> 
</table>

<%If Request.QueryString("do") = "sok" Then%>

<b>Sök resultat för: <%=Request("SearchText")%></b><br>

<%Const fsoForReading = 1

strMapp = "MAPPNAMN"

Mappen = Server.MapPath(strMapp)
MappUrl = Mid(Mappen, InStrRev(Mappen, "\") + 1)

strSearchText = Request("SearchText")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Mappen)

For Each objFile in objFolder.Files
  If Response.IsClientConnected then
    If InStr(1,objFile.Name,strSearchText,1) then
       Response.Write "<b>»</b> <a href=" & Mappen & objFile.Name & " target=""_blank"">" & objFile.Name & "</a><br>"
       bolFileFound = True
    End If
  End If
Next

Set objSubFolder = objFolder.SubFolders

For Each objSF In objSubFolder

bolFileFound = False

For Each objFile in objSF.Files
  If Response.IsClientConnected then
    If InStr(1,objFile.Name,strSearchText,1) then
       Response.Write "<b>»</b> <a href=" & Mappen & objFile.Name & " target=""_blank"">" & objFile.Name & "</a><br>"
       bolFileFound = True
    End If
  End If
Next

Next

if Not bolFileFound then Response.Write "Inga sökresultat..."

Set objFolder = Nothing
Set objFSO = Nothing
Set objSubFolder = Nothing

End If%>
```

GÅr väl iofs att göra smidigare genom att lägga det i en fuktion samt att den då kan söka ännu djupare ner. Nu klarar det ju bara en undernivå.

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

## #6 — Asa, 2003-08-01T12:50Z

Nån som vet hur man gör en funktion av detta då?

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/82480-sök-med-fso
