Posted on 2006-03-21
Last Modified: 2012-05-05

EE helped me with

is there a way that can display the contents of the folder with open/close function?thx
Question by:mcrmg
    LVL 10

    Accepted Solution

    Try this:
    (All folders are closed by default)

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


    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"


    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 = "\"
         strRelativePath = strRelativePath & "/"
      End If

      Response.Write "<blockquote>" & vbcrlf

      If IterationCount mod 20 = 0 Then
      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>"
                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
    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


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

    End Sub


    Author Comment

    Thank you

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now