When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, February 02, 2000

Generating a Web Site File System Report, Part 5


  • Read Part 1
  • Read Part 2
  • Read Part 3
  • Read Part 4


  • In Part 4 we completed our dissection of ExamineWeb.asp. Recall that ExamineWeb.asp provides a drill-down link to DetailedReport.asp on the file extension names. In this part, we'll look at the code for DetailedReport.asp!

    - continued -

    <% Option Explicit %>
    <%
    
    sub DisplayFolderContents(objFolder, bolRecurseDirectories, strExt, iCount)
      'Only process directories that do NOT start with
      'an underscore.
    
      If Not Left(objFolder.Name,1) = "_" then
         Dim objFile, strPath, strExtension
         For Each objFile in objFolder.Files
           strPath = objFile.Path
           strExtension = Ucase(Right(strPath, Len(strPath) - _
                                        InStrRev(strPath, ".")))
    
           If UCase(strExt) = strExtension then
             Response.Write iCount & ".) " & objFile.Path & " [" & _
                   "<A HREF=""ViewCode.asp?FileName=" & _
                   Server.URLEncode(objFile.Path) & _
                   """>View Code</A>]"
             Response.Write " ["
             If objFile.Size < 1000 then
               Response.Write objFile.Size & " Bytes]"
             Else
               Response.Write FormatNumber(objFile.Size/1000) & _
                           " KB]"
             End If
    
             Response.Write "<BR>"
             iCount = iCount + 1
           End If
         Next
    
         Dim objSubFolder
         If bolRecurseDirectories then
           For Each objSubFolder in objFolder.SubFolders
             DisplayFolderContents objSubFolder, bolRecurseDirectories, _
                       strExt, iCount
           Next
         End If
      End If
    end sub
    
    
      Dim objFSO
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    
      Dim bolRecurseDirectories
      bolRecurseDirectories = Request("chkRecurse")
      If bolRecurseDirectories = "on" then
        bolRecurseDirectories = True
      Else
        bolRecurseDirectories = False
      End If
    
    
      Dim strRootFolder
      strRootFolder = Server.MapPath("/")
    
      Dim objFolder
      Set objFolder = objFSO.GetFolder(strRootFolder)
    
      Set objFSO = Nothing
    
      Dim iTotal
      iTotal = 1
    %>
    
    <HTML>
    <BODY>
      <FONT SIZE=+2><B>
        Web Site File System Report
      </B></FONT><BR>
      (<I>The report was run on directory <%=strRootFolder%>.
       <% If bolRecurseDirectories then
         Response.Write "The subdirectories were recursed."
       Else
         Response.Write "The subdirectories were <b>not</b> recursed."
       End If
       %>
      </I>)
      <P><HR NOSHADE><P>
      <B><U>To view the code for one of these pages, simply click on the
      <FONT COLOR=BLUE></B>
        View Code<B></FONT>
      link.</U></B><BR>
    
    <%
      DisplayFolderContents objFolder, bolRecurseDirectories, _
                                   Request("ext"), iTotal
    
      Set objFolder = Nothing
    %>
    
      <P><HR NODSHADE><P>
      <%=iTotal - 1%> Files with Extension <%=Request("ext")%>.<BR>
      [<A HREF="ExamineWeb.asp?chkRecurse=<%=Request("chkRecurse")%>">
         Back to Report
      </A>]
    </BODY>
    </HTML>
    

    Click for a larger image! The work horse for DetailedReport.asp is a function named DisplayFolderContents. DisplayFolderContents is very similar to TraverseFolder in ExamineWeb.asp. Instead of modifying a dictionary object, however, DisplayFolderContents iterates through a folder finding those files that contain the extension specified by strExt, which is initially set to the value of Request("ext"), or the file extension name clicked on from ExamineWeb.asp.

    Notice that each file outputted contains a link to ViewCode.asp, which displays the source code of the particular file. This enables you to quickly view the source code of your HTML or ASP pages on your Web site when using this reporting feature!

    After the DisplayFolderContents function is defined, DetailedReport.asp starts by creating an instance of the FileSystemObject. Next, we determine whether or not the user is interested in recursing the subdirectories or not. We then find the physical path of the Web's root directory, and obtain an instance of the folder object representing this directory by using FSO's GetFolder method. Looks a lot like ExamineWeb.asp, doesn't it!?

    Once we've done this, we free objFSO by setting it equal to Nothing. We then create a counting variable, iTotal, and increment it to 1. Next, we break into HTML, displaying a fanciful header exactly like we did in ExamineWeb.asp. The actual file names are outputted with a single call to DisplayFolderContents.

    We conclude by freeing objFolder and displaying an informative footer containing a link back to the main report screen on ExamineWeb.asp. Recall that each file name listed in this report has a "View Code" link, which sends the user to ViewCode.asp, essentially displaying the source code of the particular file. In Part 6 we'll look at the code for ViewCode.asp.

  • Read Part 6
  • Read Part 4
  • Read Part 3
  • Read Part 2
  • Read Part 1


  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article