<%
'*******************************************************'
'* Include file Provided by Robert J Collins *'
'* *'
'* This include is a Directory Browsing tool *'
'* *'
'* Direct all inquiries to robert.collins@non.hp.com *'
'*******************************************************'
%>
<%
Dim strVal1
Dim strVal2
Dim strVal3
'This function takes a filename and returns the appropriate image for'
'that file type based on its extension. If you pass it "dir", it assumes'
'that the corresponding item is a directory and shows the folder icon.'
Function ShowImageForType(strName)
Dim strTemp
'Set our working string to the one passed in'
strTemp = strName
'If its not a directory, get the extension and set it to strTemp'
'If it is a directory, then we already have the correct value'
If strTemp <> "dir" Then '<
strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
End If
'Debugging line used to perfect that above string parser'
'Response.Write strTemp'
'Set the part of the image file name thats unique to the type of file'
'to its correct value and set this to strTemp. (yet another use of it!)'
Select Case strTemp
Case "asp"
strTemp = "asp"
Case "dir"
strTemp = "dir"
Case "htm", "html"
strTemp = "htm"
Case "gif", "jpg"
strTemp = "img"
Case "txt"
strTemp = "txt"
Case Else
strTemp = "misc"
End Select
'All our logic is done... build the IMG Tag for display to the browser'
'Place it into... where else... strTemp!'
'My images are all GIFs and all start with "dir_" for my own sanity.'
'They end with one of the values set in the select statement above.'
strTemp = "› "
'Set return value and exit function'
ShowImageForType = strTemp
End Function
'Thats it for functions on this one!'
%>
<% '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 dont'
'need you guys and gals roaming around our server so Ive 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))
'Show a little description line and the title row of our table'
%>
File Name:
File Size:
Date Created:
File Type:
<%
'Initialize strVal1 & strVal2 to there staring colors for the alternating display'
strVal1 = "beige"
strVal2 = "#FFFFFF"
strVal3 = ""
'First I deal with any subdirectories. I just display them and when you'
'click you go to them via plain HTTP. You might want to loop them back'
'through this file once you''ve set it up to take a path as input. It seems'
'like the logical thing to do to me at least!'
For Each objItem In objFolder.SubFolders
'Deal with the stupid VTIs that keep giving our visitors 404s'
If InStr(1, objItem, "_vti", 1) = 0 Then
%>
<%
End If
strVal3 = strVal1
strVal1 = strVal2
strVal2 = strVal3
Next 'objItem'
'Now that Ive done the SubFolders, do the files!'
For Each objItem In objFolder.Files
If InStr(1, objItem, "default.asp", 1) = 0 Then
If InStr(1, objItem, ".tmp", 1) = 0 Then
%>
<%
End If
End If
strVal3 = strVal1
strVal1 = strVal2
strVal2 = strVal3
Next 'objItem'
'All done! Kill off our object variables.'
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>