View Full Version : filesystemobject...

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.


dim rootPath, remoteAddr, httpHost

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 & "&nbsp;&nbsp;&nbsp;<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 & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""" & siteFolder.name & "/" & childFolder.name & "/" & childFile.name & """>" & childFile.name & "</a><BR>"
s = s & "</div>"

Set siteFiles=siteFolder.Files
For Each siteFile in siteFiles
s = s & "&nbsp;&nbsp;&nbsp;<a href=""" & siteFolder.name & "/" & siteFile.name & """>" & siteFile.name & "</a><BR>"
s = s & "</div>"
End If



<script language="javascript">
function showContents(folderName){

<body style="font-family:Verdana; font-size:10pt">

<h1><%=httpHost%> (<%=remoteAddr%>)</h1>


02-20-2003, 01:21 AM
By any chance did you look at BrainJar's script in the sticky thread "list all files in a directory"?

It's recursive, and a very, very good example of how to look in subfolders, etc. using this technique.

I learned a lot from that post, and I'm using the same technique (with slight modification) on a couple of intranet sites, with no apparent speed drawbacks.

02-20-2003, 01:13 PM
Took your advice and used the brainjar script :) It's a bit faster now, and I tweaked it to give directories an id number that I could use with the javascript.

Thanks :)