---
title: "Filhanterare - vad är fel?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/53001-filhanterare-vad-är-fel"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "JPS"
published: "2002-09-12T08:16:03.000Z"
updated: "2002-09-12T11:00:16.000Z"
replies: 6
views: 319
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/53001-filhanterare-vad-är-fel"
---

# Filhanterare - vad är fel?

## #1 — JPS, 2002-09-12T08:16Z

Hej.

Jag behöver använda IDG,s filhanterare och efter viss modifiering enligt detta forum och annan kod fungerar inte sidan om mappar har mellanslag och/eller filer innehåller mellanslag.

HJÄLP!

\<%
If Request.QueryString("path") = "" Then

StartMapp = "C:\\Inetpub\\webpub\\Snippets\\ASP_koder\\Filhanterare\\Dokument"
StartMappUrl = "http://jps/snippets/ASP_koder/Filhanterare/Dokument"

'StartMapp = "c:\\inetpub\\wwwroot\\test"
'StartMappUrl = "http://localhost/test"

Else

StartMapp = Request.QueryString("path")
StartMappUrl = Request.QueryString("url")

End If

Set filsystemobjekt = CreateObject("Scripting.FileSystemObject")
Set folder = filsystemobjekt.GetFolder(StartMapp)
Set filer = folder.Files 
Set underkataloger = folder.SubFolders 

'	Which Columns to display (True or False)
	Const DisplayColumnName     = True
	Const DisplayColumnSize     = True
	Const DisplayColumnType     = True
	Const DisplayColumnModified = True
	Const DisplayColumnSubItems = True

Function bytesize(bytes)
	If bytes \< 1024 Then
		bytesize = "1 kB"
	Else
		bytesize = FormatNumber((bytes/1024),0,-1) & " kB"
	End If
End Function

%\>
\<html\>

\<head\>
\<title\>Filhanteraren\</title\>
\<link rel="stylesheet" type="text/css" href="mall.css"\>
\</head\>

\<body bgcolor="#FFFFFF" text="#000000" vlink="#0000FF"\>

\<table border="1" width="600"\>
  \<tr\>
    \<td width="110"\>&nbsp;\</td\>
    \<td\>

    \<table border="0" width="100%"\>
      \<tr\>

	\<% If DisplayColumnName Then %\>
	\<td bgcolor="#FFFFDF"\>Namn\</td\>
	\<% End If %\>

	\<% If DisplayColumnSize Then %\>
	\<td bgcolor="#FFFFDF"\>Storlek\</td\>
	\<% End If %\>
	\<% If DisplayColumnType Then %\>
        	\<td bgcolor="#FFFFDF"\>Typ\</td\>
	\<% End If %\>
	\<% If DisplayColumnModified Then %\>
        	\<td bgcolor="#FFFFDF"\>Ändrad\</td\>
      	\<% End If %\>

\</tr\>
\<tr\>
\<%
For Each folder in underkataloger

' Nedan kontrollerar vi så att det inte visas några mappar med konstiga attribut

If folder.Attributes \< 50 then
%\>
        \<td\>\<img src="images/Icon_folder.gif" align="absmiddle"\>
\<% Response.Write "\<a href=""index.asp?url=" & server.urlencode(StartMappUrl) & "/" & server.urlencode(folder.name) & "&path=" & server.urlencode(StartMapp) & "\\" & folder.name & """\>" & folder.name & "\</a\> \<br\>"  %\>

\</font\>\</td\>
 
       \<td\>\<font face="Verdana"\>\<%= bytesize(Folder.size) %\> \</font\>\</td\>
       \<td\>\<font face="Verdana"\>Filmapp\</font\>\</small\>\</small\>\</td\>
       \<td\>\<font face="Verdana"\>\<%= FormatDateTime(folder.DateCreated, 2)%\>\</font\>\</td\>
 
\</tr\>
\<%
end if
Next  
%\>
\<%
For Each folder in filer

' Nedan kontrollerar vi så att det inte visas några filer med konstiga attribut

If folder.Attributes \< 50 then
%\>
      \<tr\>
        \<td\>\<img src="images/\<%=FileIcon%\>.gif"\>\<img src="images/dokument.gif" align="absmiddle" WIDTH="13" HEIGHT="16"\>\<font face="Verdana"\>\<% Response.Write "\<a href=" & StartMappUrl & "/" & folder.name &  "\>" & folder.name & "\</a\> \<br\>" %\> \</font\>\</td\>
        \<td\>\<font face="Verdana"\>\<%= bytesize(Folder.size) %\> \</font\>\</td\>
        \<td\>\<font face="Verdana"\>\<%= folder.Type %\> \</font\>\</td\>
        \<td\>\<font face="Verdana"\>\<%= FormatDateTime(folder.DateCreated, 2) %\> \</font\>\</small\>\</small\>\</td\>
      \</tr\>
\<%
end if
Next  
%\>
    \</table\>
    \<p\>&nbsp;\</p\>
    \<p\>&nbsp;\</p\>
    \<p align="right"\>&nbsp;\</td\>
  \</tr\>
\</table\>
\</body\>
\</html\>

\<%
Set filsystemobjekt = Nothing
Set folder = Nothing
Set filer = Nothing
Set underkataloger = Nothing
%\>

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

## #2 — @nders, 2002-09-12T08:23Z

```
<% Response.Write "<a href=""index.asp?url=" & server.urlencode(StartMappUrl) & "/" & server.urlencode(folder.name) & "&path=" & server.urlencode(StartMapp) & "\" & [b]Server.URLEncode(folder.name)[/b] & """>" & folder.name & "</a> <br>" %>
```

Använd \[ kod\]-taggar så blir din kod betydligt lättare att läsa.

Mvh,

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

## #3 — JPS, 2002-09-12T08:36Z

Tyvärr den kapar ändå länkarna både på mappar och filer.

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

## #4 — @nders, 2002-09-12T08:39Z

Du får se till att köra Server.URLEncode på alla ställen där du skriver ut länkar, på precis samma sätt som kodraden jag postade.

Mvh,

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

## #5 — JPS, 2002-09-12T08:52Z

Jag satte in koden med det funkar ändå inte :-\[

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

## #6 — @nders, 2002-09-12T09:45Z

Hur ser koden ut nu då, efter ändringar?

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

## #7 — JPS, 2002-09-12T11:00Z

Tackar för hjälpen.

Jag får det inte att fungera så jag gick ut på nätet och hittade en annan version.

Håll till godo och tack för hjälpen.

```

<%
	'Set this to the home directory in relationship to the script.
	'You cannot have the directory set to up one directory (ie "../") for security reasons unless you disable "Security" below.
	'Note that if your file home directory is up one level the script may not function properly.
	HomeDir = "files"
	'Do not put a "/" on the end of this!
	'Do not edit below this line unless you know what you're doing.
	Security = "On"
	'If you do not want users browsing directories up one level from the specified one, set this to "On".
	'Otherwise, set it to "Off"
	CurrentDir = Request.QueryString("dir")
	if Left(CurrentDir, 3) = "../" and Security = "On" then
	Response.Write "You are not permitted to browse this directory."
	else
	Set FSO = Server.CreateObject("Scripting.FileSystemObject")
	if CurrentDir = "" then
	CurrentDir = HomeDir
	Set BrowseContents = FSO.GetFolder(Server.MapPath(HomeDir))
	else
	Set BrowseContents = FSO.GetFolder(Server.MapPath(CurrentDir))
	end if
	
	
Function bytesize(bytes)
	If bytes < 1024 Then
		bytesize = "1 kB"
	Else
		bytesize = FormatNumber((bytes/1024),0,-1) & " kB"
	End If
End Function
	
'	Which Columns to display (True or False)
	Const DisplayColumnName     = True
	Const DisplayColumnSize     = True
	Const DisplayColumnType     = True
	Const DisplayColumnModified = True
	Const DisplayColumnSubItems = True	
	
%>

<html>

<head>
<title>Filhanteraren</title>
<link rel="stylesheet" type="text/css" href="mall.css">
</head>

<body bgcolor="#FFFFFF" text="#000000" vlink="#0000FF">

<table border="1" width="800">
  <tr>
    <td width="110">&nbsp;</td>
    <td>

	Sökväg: <%=CurrentDir%><br>

	<%
	if not CurrentDir = HomeDir then
	UpOneDirBegPos = InStrRev(CurrentDir, "/")
	UpOneDirTotal = len(CurrentDir)
	UpOneDirPath = Left(CurrentDir, UpOneDirBegPos - 1)
	Response.Write "<b>&laquo;</b> <A HREF=""?dir=" & UpOneDirPath & """>Upp en nivå</A>"
	end if
	%>	
	
<br><br>
	
   <table border="1" width="100%">
      <tr>

	<% If DisplayColumnName Then %>
	<td bgcolor="#FFFFDF">Namn</td>
	<% End If %>

	<% If DisplayColumnSize Then %>
	<td bgcolor="#FFFFDF">Storlek</td>
	<% End If %>
	
	<% If DisplayColumnType Then %>
    <td bgcolor="#FFFFDF">Typ</td>
	<% End If %>
	
	<% If DisplayColumnModified Then %>
   	<td bgcolor="#FFFFDF">Ändrad</td>
	<% End If %>

</tr>
	
	
<%
	
	for each BrowsedFolder in BrowseContents.SubFolders
	if BrowsedFolder.Name <> "_vti_cnf" then
	Response.Write "<tr>"
	Response.Write "<td><IMG SRC=""images/Icon_Folder.gif"">&nbsp;<A HREF=""?dir=" & CurrentDir & "/" & BrowsedFolder.Name & """>" & BrowsedFolder.Name & "</A>"
	Response.Write "</td><td align=""right"">"
	Response.Write BrowsedFolder.Size \ 1024 & "kB</td>"
	Response.Write "<td>Filmapp</td>"
	Response.Write "<td>" & FormatDateTime(BrowsedFolder.DateCreated, 2) & " </td></tr>"	
	ContainsSomething = "True"
	end if
	next
	
	for each BrowsedFile in BrowseContents.Files
	FileExtBegPos = InStrRev(BrowsedFile.Name, ".")
	FileExtTotal = len(BrowsedFile.Name)
	FileExt = Right(BrowsedFile.Name, FileExtTotal - FileExtBegPos)
	
	select case FileExt
	case "asp"
	FileIcon = "aspicon.gif"
	case "htm", "html", "shtm", "shtml"
	FileIcon = "htmlicon.gif"
	case "jpg", "jpeg", "gif", "png", "bmp"
	FileIcon = "imgicon.gif"
	case "zip", "rar", "tar", "gz"
	FileIcon = "zipicon.gif"
	case "exe"
	FileIcon = "exeicon.gif"
	case "mp3", "wav", "rm", "wmv"
	FileIcon = "mp3icon.gif"
	case else
	FileIcon = "icon.gif"
	end select
	
	Response.Write "<tr>"
	Response.Write "<td><img src=""images/" & FileIcon & """>&nbsp;<A HREF=""" & CurrentDir & "/" & BrowsedFile.Name & """>" & BrowsedFile.Name & "</A>"
	Response.Write "</td><td align=""right"">"
	Response.Write BrowsedFile.Size \ 1024 & " kB</td>"

	Response.Write "<td>" & BrowsedFile.type &"</td>"
	Response.Write "<td>" & FormatDateTime(BrowsedFile.DateCreated, 2) & " </td></tr>"		
	
	ContainsSomething = "True"
	next

	Response.Write "</table>"
	
	if ContainsSomething <> "True" then
	Response.Write "<TABLE WIDTH=""100%""><TR><TD><br><br>Det finns inga filer i denna mapp.</TD></TR></TABLE>"
	end if
%>

	</td>
</tr>
</table>
</body>
</html>

<%
	Set FSO = Nothing
	Set BrowseContents = Nothing
	end if
%>
```

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

---

Tråden på webben: https://www.webforum.nu/amne/asp/53001-filhanterare-vad-är-fel
