<%@ Language="VBScript" %>
<html>
<head>
<title><%= Request.ServerVariables("SERVER_NAME") %> :: Webserver Directory Listing</title>
<style type="text/css">
<!--
.bodytext { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-style: normal; color: #000000}
.caseheading { font-family: Verdana; font-size: 10pt; font-style: normal; font-weight: bold; color: #3b2ea0}
.threadtext { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-style: normal; color: #000000}
.boldbody { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-style: normal; line-height: normal; font-weight: bold; color: #000000; text-decoration: none}
.hyperlink { font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-style: normal; color: #3b2ea0; text-decoration: underline}
-->
</style>
</head>
<body>
<%
Sub folderDetails(folderName, indent)
Dim fSystem, fObject, fFolder, fFiles, fIndent, newIndent, newSize
fIndent = ""
' Indent the directory by 3
newIndent = indent + 3
Set fSystem = Server.CreateObject("Scripting.FileSystemObject")
' Get the specified folder
Set fObject = fSystem.GetFolder(Server.MapPath("" & folderName & ""))
' Set a string of non-breaking spaces for the indent
For i = 0 To indent
fIndent = fIndent & " "
Next
' Loop through the subfolders
For Each fFolder In fObject.SubFolders
' Output the subfolder name
Response.Write("<tr><td colspan='3'>" & fIndent & " - <span class='hyperlink' style='text-decoration:none'>" & fFolder.Name & "</span></td></tr>")
' Call the folderDetails Sub using the current subfolder <-- Iteration
folderDetails folderName & fFolder.Name & "/", newIndent
Next
' Loop through the files in the folder
For Each fFiles In fObject.Files
' Output the file's name
Response.Write("<tr class='threadtext'><td>" & fIndent & " - " & fFiles.Name & "</td>")
' Divide the file size by 1024 to get the size in kilobytes
newSize = fFiles.Size / 1024
' Output the file's size
Response.Write("<td>" & Round(newSize, 1) & " kb</td>")
' Ouput some file types different to standard ones to save space and aesthetics
Select Case fFiles.Type
Case "JPEG Image":
Response.Write("<td>jpeg Image</td>")
Case "GIF Image":
Response.Write("<td>gif Image</td>")
Case "Microsoft HTML Document 5.0":
Response.Write("<td>HTML Document</td>")
Case "Cascading Style Sheet Document":
Response.Write("<td>CSS Document</td>")
Case "ASP auto file":
Response.Write("<td>ASP source</td>")
Case "INC File":
Response.Write("<td>Include File</td>")
Case "JScript Script File":
Response.Write("<td>Javascript File</td>")
Case Else :
Response.Write("<td>" & fFiles.Type & "</td>")
End Select
' Output the date last modified
Response.Write("<td>" & fFiles.DateLastModified & "</td></tr>")
Next
Set fObject = Nothing
Set fSystem = Nothing
End Sub
' Build a table to show the directory listing
Response.Write("<table width='100%'>")
' Output the headings for the table
Response.Write("<tr class='caseheading'><td> Name</td><td>Size</td><td>Type</td><td>Last Modified</td></tr>")
Response.Write("<tr><td> </td></tr>")
' Call folderDetails Sub with the root directory, so that it iterates through all the directories on the server
folderDetails "/", 0
' End the table
Response.Write("</table>")
%>
</body>
</html>