<%@ LANGUAGE="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<% '***************************************************************************
   '* ASP Directory Listing                                                   *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 1999, 2000 by Mike Hall.                                      *
   '* Please see http://www.brainjar.com for documentation and terms of use.  *
   '***************************************************************************
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ASP Directory Listing Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/common/default.css" />
</head>
<body>

<div id="demoBox">

<h3>ASP Directory Listing Demo</h3>

<p>Three separate directories from the web server root are displayed below
("asp", "dhtml" and "js"), showing all subdirectories and files. Additionally,
each file is displayed as a link.</p>

</div>

<!-- List these three folders. -->
<ul>
<% ListFolderContents(Server.MapPath("/asp")) %>
<% ListFolderContents(Server.MapPath("/dhtml")) %>
<% ListFolderContents(Server.MapPath("/js")) %>
</ul>

</body>
</html>

<% sub ListFolderContents(path)

     dim fs, folder, file, item, url

     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)

    'Display the target folder and info.

     Response.Write("<li><b>" & folder.Name & "</b> - " _
       & folder.Files.Count & " files, ")
     if folder.SubFolders.Count > 0 then
       Response.Write(folder.SubFolders.Count & " directories, ")
     end if
     Response.Write(Round(folder.Size / 1024) & " KB total." _
       & vbCrLf)

     Response.Write("<ul>" & vbCrLf)

     'Display a list of sub folders.

     for each item in folder.SubFolders
       ListFolderContents(item.Path)
     next

     'Display a list of files.

     for each item in folder.Files
       url = MapURL(item.path)
       Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " _
         & item.Size & " bytes, " _
         & "last modified on " & item.DateLastModified & "." _
         & "</li>" & vbCrLf)
     next

     Response.Write("</ul>" & vbCrLf)

     Response.Write("</li>" & vbCrLf)

   end sub

   function MapURL(path)

     dim rootPath, url

     'Convert a physical file path to a URL for hypertext links.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

   end function %>