PDA

View Full Version : How do I List c:/ folder as links


pob2004
05-22-2004, 09:44 AM
I would like a script that lists a local folder as html links in a tree like format.

I found a script from shakim that lists a www. folder as a tree but does anyone an alternative script or can you modify this one.

Here is the code.
______________________________________________________________

<%@ LANGUAGE="VBScript" %>

<%

dim foldercount
foldercount=0

dim rootPath, remoteAddr, httpHost
rootPath=Server.Mappath(".")
remoteAddr=Request.ServerVariables("REMOTE_ADDR")
httpHost=Request.ServerVariables("HTTP_HOST")

%>

<html>
<head>
<title><%=httpHost%></title>

<script language="javascript">
function showContents(folderName){
//alert(folderName);
if(document.all[folderName].style.display=="block"){
document.all[folderName].style.display="none";
}
else{
document.all[folderName].style.display="block";
}
}
</script>

</head>
<body style="font-family:Tahoma; font-size:10px;">

<ul>
<% ListFolderContents(rootPath) %>
</ul>

</body>
</html>

<%

sub ListFolderContents(path)

dim fs, folder, file, item, url, strFolderInfo, strFileInfo

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

'Display the target folder and info.
strFolderInfo="<b><a href=""#"" onClick=""javascript:showContents('fol"&foldercount&"')"" title="""
if folder.SubFolders.Count > 0 then
strFolderInfo=strFolderInfo & folder.SubFolders.Count & " directories" & vbCrLf
end if
strFolderInfo=strFolderInfo & folder.Files.Count & " files" & vbCrLf
strFolderInfo=strFolderInfo & Round(folder.Size / 1000) & " KB"
strFolderInfo=strFolderInfo & """>"&folder.Name&"</a></b>"
Response.Write("<li>")
Response.Write(strfolderInfo)



Response.Write("<div id=""fol"&foldercount&""" style=""display:none;""><ul>" & vbCrLf)

'Display a list of sub folders.
for each item in folder.SubFolders
foldercount=foldercount+1
ListFolderContents(item.Path)
next

'Display a list of files.
for each item in folder.Files
url = MapURL(item.path)
strFileInfo="<li><a href="""& url & """ title="""
strFileInfo=strFileInfo & item.Size & " bytes" & vbCrLf
strFileInfo=strFileInfo & "Last modified" & item.DateLastModified & vbCrLf
strFileInfo=strFileInfo & """>"&item.Name&"</a></li>"& vbCrLf
response.write(strFileInfo)
next

Response.Write("</ul></div>" & vbCrLf)
Response.Write("</li>" & vbCrLf)

end sub

function MapURL(path)

dim rootPath, url

'Convert a physical file path to a URL for hypertext links.

rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")

end function %>

Garadon
05-22-2004, 11:09 AM
as your scripts clearly states it vbScript this is a javascript Forum, but I can tell you javascript can't do that.

pob2004
05-22-2004, 11:53 AM
Sorry your are totaly right.

I saw the words Javascript and placed it thinking you guys would know, but I will go back to trawling the net for any info on this.

Thanks for looking though.

swmr
05-22-2004, 08:44 PM
I would like a script that lists a local folder as html links in a tree like format.

I know of a couple ways to do that; HTA required. ;)