TreeView

Hi,

EE helped me with http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21704165.html

is there a way that can display the contents of the folder with open/close function?thx
mcrmgAsked:
Who is Participating?
 
thefritterfatboyCommented:
Try this:
(All folders are closed by default)

<%@ Language = VBScript %>
<% option explicit %>

<html>
<body>
<%

Dim FileCount, FolderCount, TimeStart, TimeEnd, TotalSpace, IterationCount, strRelativePath, File, Folder

FileCount = 0
FolderCount = 0
TotalSpace = 0
IterationCount = 0

TimeStart = Timer()

Call PrintFolderStructure(Server.Mappath("."))

TimeEnd = Timer()

Response.Write "<br><br>Total Folders: " & FolderCount
Response.Write "<br>Total Files: " & FileCount
Response.Write "<br>Space Used: " & FormatNumber(TotalSpace/1024,0) & " Kb"
Response.Write "<br>Time: " & FormatNumber(TimeEnd - TimeStart,2) & " Seconds"


%>
</body>
</html>
<%

Sub PrintFolderStructure(path)

  dim objFSO, objFolder, rootPath, strCurrentPath

  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

  Set objFolder = objFSO.GetFolder(path)
 
   IterationCount = IterationCount + 1
  Response.Write vbCrLf
 
  'Get virtual root

  rootPath = Server.MapPath(".")

  strCurrentPath = Mid(path,len(rootPath)+1)
  strRelativePath = strCurrentPath

  If len(strCurrentPath) = 0 Then
      strCurrentPath = "\"
  Else
     strRelativePath = strRelativePath & "/"
  End If

  Response.Write "<blockquote>" & vbcrlf

  If IterationCount mod 20 = 0 Then
     Response.Flush
  End If
  dim isFolderOpen
  isFolderOpen = (clng(request.querystring("open")) = -1)

  Response.Write "<b><a href=""" & request.servervariables("SCRIPT_NAME") & "?path=" & strCurrentPath & "&open="
      if isFolderOpen and request.querystring("path") = strCurrentPath then
            response.write clng(false) & """>" & strCurrentPath & "</a></b><br>"
      else
            response.write clng(true) & """>" & strCurrentPath & "</a></b><br>"
      end if


if isFolderOpen and request.querystring("path") = strCurrentPath then

   For Each File in objFolder.Files
    'This code runs for each file in a folder
        FileCount = FileCount + 1
        TotalSpace = TotalSpace + File.Size
        Response.Write "<a href=" & chr(34) & Replace(strRelativePath,"\","/") & File.Name  & chr(34) & " >" & File.Name & "</a>&nbsp;&nbsp; (<i style=""font-size: small;"">" & File.DateLastModified & ") " & FormatNumber(File.Size,0) & " bytes</i><br>" & vbCrLf
  Next
end if
  For Each Folder in objFolder.SubFolders

   'This code runs for each subfolder


      'Sub calls itself passing the path of the subfolder
       FolderCount = FolderCount + 1
       PrintFolderStructure(Folder.Path)

  Next

  Response.Write "</blockquote>"
 
   Set objFSO = Nothing

End Sub


'PrintFolderStructure("c:/inetpub/")
%>
0
 
mcrmgAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.