Directory Listing
<%' Now to the Runtime code:
Dim strPath 'Path of directory to show
Dim objFSO 'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder
' You could just as easily read this from some sort of input, but I don't
' need you guys and gals roaming around our server so I've hard coded it to
' a directory I set up to illustrate the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = "./"
' Create our FSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
' Get a handle on our folder
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
%>
<BR>
<TABLE BORDER="5" BORDERCOLOR="green" CELLSPACING="0" CELLPADDING="2">
<TR BGCOLOR="#006600">
<TD></TD>
</TR>
<%
' First I deal with any subdirectories. I just display them and when you
' click you go to them via plain HTTP.
For Each objItem In objFolder.SubFolders
' Deal with the stupid VTI's that keep giving our visitors 404's
If InStr(1, objItem, "_vti", 1) = 0 Then
%>
<TR BGCOLOR="#CCFFCC">
<TD ALIGN="left" ><A HREF="<%= strPath & objItem.Name %>"><%= objItem.Name %></A></TD>
</TR>
<%
End If
Next 'objItem
' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</TABLE>