This function will count all the files in the ActiveWeb.
It will put them into a two dimensional array. The Extension name will go in the first dimension. The second dimension will be incrementally increased every time another file with that extension is found.
The redim preserve statement will redimension the second dimension of the array. It will increase the second dimension by a value of one each time a file with a new extension type is found.
Then it will call another function to sort the array.
After that it will put the total for all file types in the last element.
Function GetNumberOfFilesByType() As Variant
'Tested 20090208
On Error GoTo errHandler1
Dim i, j As Integer
Dim intTotal As Integer
Dim intExtCounter As Integer
Dim intCopyRow As Integer
Dim strExt As String
Dim strPrompt As String
Dim blnFound As Boolean
Dim arrGeneral As Variant
intCopyRow = 0
blnFound = False
intExtCounter = 0
'Redimension array to 2 columns
'and 2 rows (zero based).
ReDim arrGeneral(1, 1)
For i = 0 To WebDesigner.ActiveWeb. _
AllFiles.Count - 1
strExt = WebDesigner.ActiveWeb. _
AllFiles(i).Extension
'Loop through the array to see if that
'extension has already been entered.
For j = 0 To intExtCounter - 1
If strExt = arrGeneral(0, j) Then
'Increment the number of files in the
'second column by 1 for the j row.
arrGeneral(1, j) = arrGeneral(1, j) + 1
blnFound = True
End If
Next j
'That extension was not found,
'so add it to next array element
If blnFound = False Then
'Add the extension name
'to the first column
arrGeneral(0, intExtCounter) = strExt
'Put 1 in the second column.
'designating the count is 1.
arrGeneral(1, intExtCounter) = 1
'increment the row counter by 1
intExtCounter = intExtCounter + 1
ReDim Preserve _
arrGeneral(1, intExtCounter)
End If
blnFound = False
Next i
'sort the array by file numbers.
'Put the element with the largest
'number of files first.
arrGeneral = GetArrSort(arrGeneral)
'Put the totals in the last element
'of the array.
For j = 0 To UBound(arrGeneral, 2) - 1
intTotal = intTotal + arrGeneral(1, j)
Next j
arrGeneral(1, UBound(arrGeneral, 2)) = _
intTotal
GetNumberOfFilesByType = arrGeneral
Exit Function
errHandler1:
'Notify user of failure.
MsgBox "GetNumberOfFilesByType has failed", _
vbCritical, "Function Failure"
End Function
The array values are shown below.
0 htm 111 1 jpg 20 2 frm 4 3 frx 4 4 css 1 5 140
Array element (0,0) contained the value "htm" and array element (1,0) contained 111.
Array element (0,1) contained the value "jpg" and array element (1,1) contained 20.
Array element (0,2) contained the value "frm" and array element (1,2) contained 4.
Array element (0,3) contained the value "frx" and array element (1,3) contained 4.
Array element (0,4) contained the value "fcss and array element (1,5) contained 1.
Array element (0,5) contained the value "" and array element (1,5) contained 140, the total of the above file types.
If I had not sorted the array, the output would have been:
0 htm 111 1 css 1 2 jpg 20 3 frm 4 4 frx 4 5 140