Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    filesystemobject...

    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.

    Code:
    <%@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 & "&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>"
    			Next
    			s = s & "</div>"
    		Next
    		
    		Set siteFiles=siteFolder.Files
    		For Each siteFile in siteFiles
    			s = s & "&nbsp;&nbsp;&nbsp;<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>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by whammy; 02-20-2003 at 01:27 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •