<%
Class cDirectoryList
Private oFS
Private m_sRootpath
Private m_oRootFolder
Private b_Initialized
Private aFolderArray() ' Array of SubFolder Paths
Private sWorkingPath
Private bTraverseChildren 'Not used in Current version
'======================================
' Class Properties
'======================================
Public Property Get sRootPath()
sRootpath = m_sRootpath
End Property
Public Property Let sRootPath(sInput)
m_sRootpath = sInput
End Property
Private Property Set oRootFolder(oInput)
Set m_oRootFolder = oInput
End Property
Private Property Get oRootFolder()
Set oRootFolder = m_oRootFolder
End Property
'============================
' Initialization
'============================
Private Sub Class_Initialize()
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
b_Initialized = False
bTraverseChildren = True
ReDim Preserve aFolderArray(0)
sWorkingPath = Left(Request.ServerVariables("PATH_TRANSLATED"), InStrRev(Request.ServerVariables("PATH_TRANSLATED"), "\"))
End Sub
'==========================
' Cleanup
'==========================
Private Sub Class_Terminate()
If isObject(oFS) Then Set oFS = Nothing
End Sub
Private Sub Init()
If b_Initialized = False Then
Set oRootFolder = oFS.GetFolder(Server.mapPath(sRootPath))
b_Initialized = True
End If
End Sub
'===========================
' Class Members
'===========================
Sub GetSubFolders(oParent)
Call Init()
'On Error Resume Next
If oParent = "" Then
Set oParent = oRootFolder
End IF
Dim oSubFolder
If sRootPath = "" Then
Echo("ERROR: Specify a root folder.")
Response.End()
End If
Dim iSubFolderCount
Dim iCurrentIndex
Dim iIterator
'=======================
' Update Array bounds
'=======================
iCurrentIndex = UBound(aFolderArray)
iSubFolderCount = (oParent.SubFolders.Count + iCurrentIndex)
ReDim Preserve aFolderArray(iSubFolderCount)
IF oParent.Path = oRootFolder.Path Then
aFolderArray(iCurrentIndex) = oParent.Path
End IF
For Each oSubFolder In oParent.SubFolders
iCurrentIndex = (iCurrentIndex + 1)
aFolderArray(iCurrentIndex) = oSubFolder.Path
If oSubFolder.SubFolders.Count > 0 Then
Call GetSubFolders(oSubFolder)
End If
Next
End Sub
Private Sub GetFiles(sPath)
Dim oFolder, oFile
Dim iIterator
For iIterator = 0 To UBound(aFolderArray)
Set oFolder = oFS.GetFolder(aFolderArray(iIterator))
Echo("<B>" & NormalizePath(aFolderArray(iIterator)) & "</B><BR>")
For Each oFile In oFolder.Files
Echo(" <a href=" & Chr(34) & NormalizePath(aFolderArray(iIterator)) & "/" & oFile.Name & Chr(34) & ">" _
& oFile.name & "</a><BR>")
Next
Next
End Sub
Public Sub DisplayFolders()
Dim x
For x = 0 To UBound(aFolderArray)
GetFiles(aFolderArray(x))
Next
End Sub
Private Function NormalizePath(sPath)
NormalizePath = Replace(Mid(sPath, Len(sWorkingPath), Len(sPath)), "\", "/")
End Function
Private Sub Echo(sInput)
Response.Write(sInput & vbCrLf)
End Sub
End Class
Dim oDirLister
Set oDirLister = New cDirectoryList
oDirLister.sRootPath = "\" 'Virtual Root
oDirLister.GetSubFolders ""
oDirLister.DisplayFolders
Set oDorLister = nothing
%>