View Full Version : how display the folder as tree
bmwmpower
04-23-2003, 09:15 AM
i have some folder in main folder i want display this folder as tree like the explore in the windows
Spudhead
04-23-2003, 05:29 PM
I think the sticky thread at the top about listing files in a directory covers this fairly well, but (just for fun), here's the page I use (It's based around a slightly-cannibalised version of a script in the above-mentioned thread). It builds up a collapsible menu based around my wwwroot folder. IE only, but hey ;)
<%@ 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 %>
elcaro2k
05-02-2003, 05:03 PM
This code is working great, but is there a way to hide the .asp page that this code is in?
What do you mean, is there a way to hide the .asp page that this code is in?
Hide it from who? The script runs serversided and sends html ans javascript to the browser, not asp-code. (check the source in your browser, and you'll see the difference)
elcaro2k
05-05-2003, 02:49 PM
When the users views the files in the tree, I only want them to see .pdf's.
I have already found a solution, Thanks!!!
arnyinc
05-05-2003, 04:48 PM
I know I should just leave well enough alone, but is anyone else wondering if the first question "This code is working great, but is there a way to hide the .asp page that this code is in?" is in ANY way related to the eventual goal of only displaying .pdfs.
elcaro2k
05-05-2003, 04:56 PM
I agree it was a poor choice of words but it had been a long week. The way it was working before is that when the directory tree was displayed, it would show the list of .pdf's and the treeviewer.asp. Treeviewer.asp is the page in which the above code resides. I donot want my users to see my asp page, I only want them to see the pdf's.
arnyinc
05-05-2003, 05:03 PM
Now I get it. I'm too picky.
whammy
05-06-2003, 12:46 AM
Ahh... all you'd have to do is only show the extensions that matched "pdf"...
see here:
http://www.w3schools.com/asp/asp_ref_filesystem.asp
elcaro2k
05-06-2003, 03:32 PM
How is the best way to use the above code in a frame on the left side of a page and view the pdf's on the right side of the page?
Thanks,
Ray
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.