Spudhead
02-19-2003, 05:11 PM
Like any respectable developer, I'm forever building things and then breaking them. Indeed, the two phases are often indistinguishable. I thus present my latest effort, an index.asp for my localhost, which allows me to view all the sub-sites, microsites, development sites, archive sites and miscellaneous carp that sit in my wwwroot.
I have two questions about it, both of which I feel could be well answered by "You should have sat down and thought about this before trying to kludge it together".
Firstly, is the time it takes. It originally listed site folders in the root folder, quickly. Then it listed files within the site folders, not so quickly. Now it lists subfolders, and the files within them, within the site folders. And it takes AGES; about 3 minutes usually. And it's running locally.
Second, is the simple javascript that hides/shows folder contents. The specific problem with this is that I'm naming the content div's after the folder names, and if there are folders with the same names (and there are - most, for example, have an 'images' folder) my javascript gets all confused and throws its toys out if its pram.
Anyway, here's the...stuff.
<%@LANGUAGE=VBSCRIPT%>
<%
dim rootPath, remoteAddr, httpHost
rootPath=Server.Mappath(".")
remoteAddr=Request.ServerVariables("REMOTE_ADDR")
httpHost=Request.ServerVariables("HTTP_HOST")
dim fso, root, siteFolders, siteFolder, siteFiles, siteFile, subFolders, subFolder
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set root = fso.GetFolder(rootPath)
Set siteFolders = root.SubFolders
For Each siteFolder in siteFolders
If siteFolder.name<>"_private" And siteFolder.name<>"_vti_cnf" And siteFolder.name<>"_vti_log" And siteFolder.name<>"_vti_script" And siteFolder.name<>"_vti_pvt" And siteFolder.name<>"_vti_txt" And siteFolder.name<>"images" Then
s = s & "<b><a href=javascript:showContents('" & siteFolder.name &"')>" & siteFolder.name & "</a></b><BR>"
s = s & "<div id="""&siteFolder.name&""" style=""display:none;"">"
Set childFolders=siteFolder.SubFolders
For Each childFolder in childFolders
s = s & " <b><a href=javascript:showContents('" & childFolder.name &"')>" & childFolder.name & "</a></b><BR>"
s = s & "<div id="""&childFolder.name&""" style=""display:none;"">"
Set childFiles=childFolder.Files
For Each childFile in childFiles
s = s & " <a href=""" & siteFolder.name & "/" & childFolder.name & "/" & childFile.name & """>" & childFile.name & "</a><BR>"
Next
s = s & "</div>"
Next
Set siteFiles=siteFolder.Files
For Each siteFile in siteFiles
s = s & " <a href=""" & siteFolder.name & "/" & siteFile.name & """>" & siteFile.name & "</a><BR>"
Next
s = s & "</div>"
End If
Next
%>
<html>
<head>
<title><%=httpHost%></title>
<script language="javascript">
function showContents(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:Verdana; font-size:10pt">
<h1><%=httpHost%> (<%=remoteAddr%>)</h1>
(<%=rootPath%>)<br>
<br>
<%=s%>
</body>
</html>
I have two questions about it, both of which I feel could be well answered by "You should have sat down and thought about this before trying to kludge it together".
Firstly, is the time it takes. It originally listed site folders in the root folder, quickly. Then it listed files within the site folders, not so quickly. Now it lists subfolders, and the files within them, within the site folders. And it takes AGES; about 3 minutes usually. And it's running locally.
Second, is the simple javascript that hides/shows folder contents. The specific problem with this is that I'm naming the content div's after the folder names, and if there are folders with the same names (and there are - most, for example, have an 'images' folder) my javascript gets all confused and throws its toys out if its pram.
Anyway, here's the...stuff.
<%@LANGUAGE=VBSCRIPT%>
<%
dim rootPath, remoteAddr, httpHost
rootPath=Server.Mappath(".")
remoteAddr=Request.ServerVariables("REMOTE_ADDR")
httpHost=Request.ServerVariables("HTTP_HOST")
dim fso, root, siteFolders, siteFolder, siteFiles, siteFile, subFolders, subFolder
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set root = fso.GetFolder(rootPath)
Set siteFolders = root.SubFolders
For Each siteFolder in siteFolders
If siteFolder.name<>"_private" And siteFolder.name<>"_vti_cnf" And siteFolder.name<>"_vti_log" And siteFolder.name<>"_vti_script" And siteFolder.name<>"_vti_pvt" And siteFolder.name<>"_vti_txt" And siteFolder.name<>"images" Then
s = s & "<b><a href=javascript:showContents('" & siteFolder.name &"')>" & siteFolder.name & "</a></b><BR>"
s = s & "<div id="""&siteFolder.name&""" style=""display:none;"">"
Set childFolders=siteFolder.SubFolders
For Each childFolder in childFolders
s = s & " <b><a href=javascript:showContents('" & childFolder.name &"')>" & childFolder.name & "</a></b><BR>"
s = s & "<div id="""&childFolder.name&""" style=""display:none;"">"
Set childFiles=childFolder.Files
For Each childFile in childFiles
s = s & " <a href=""" & siteFolder.name & "/" & childFolder.name & "/" & childFile.name & """>" & childFile.name & "</a><BR>"
Next
s = s & "</div>"
Next
Set siteFiles=siteFolder.Files
For Each siteFile in siteFiles
s = s & " <a href=""" & siteFolder.name & "/" & siteFile.name & """>" & siteFile.name & "</a><BR>"
Next
s = s & "</div>"
End If
Next
%>
<html>
<head>
<title><%=httpHost%></title>
<script language="javascript">
function showContents(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:Verdana; font-size:10pt">
<h1><%=httpHost%> (<%=remoteAddr%>)</h1>
(<%=rootPath%>)<br>
<br>
<%=s%>
</body>
</html>