Method 3 of 4 Reference methods

This method uses with ...end with blocks  to qualify the object path.

Sub FoldersAndFiles3()
  Dim h As Integer
  Dim i As Integer
  Dim j As Integer
  Dim k As Integer
  Dim l As Integer
  Dim strH As String
  Dim strI As String
  Dim strJ As String
  Dim strK As String
  Dim strL As String

  h = 0
  With WebDesigner.Application. _
  ActiveWeb.AllFolders.Item(h)
    Debug.Print "Folder " & h & ". named " & _
    .Name & _
    " has " & _
    .Files.Count & _
    " files."

    For i = 0 To .Folders.Count - 1
      With .Folders.Item(i)
        strI = _
        vbTab & _
        "Folder " & h & "." & i & ". named " & _
        .Name & _
        " has " & _
        .Files.Count & _
        " files."
        Debug.Print strI

        For j = 0 To .Folders.Count - 1
          With .Folders.Item(j)
            strJ = _
            vbTab & _
            vbTab & _
            "Folder " & h & "." & i & "." & _
            j & ". named " & _
            .Name & _
            " has " & _
            .Files.Count & _
            " files."
            Debug.Print strJ

            For k = 0 To .Folders.Count - 1
              With .Folders.Item(k)
                strK = _ 
                vbTab & _ 
                vbTab & _
                vbTab & _
                "Folder " & h & "." & i & "." & _
                j & "." & k & ". named " & _
                .Name & _
                " has " & _
                .Files.Count & _
                " files."
                 Debug.Print strK

                For l = 0 To .Folders.Count - 1
                  With .Folders.Item(l)
                    strL = _ 
                    vbTab & _ 
                    vbTab & _
                    vbTab & _
                    vbTab & _
                    "Folder " & h & "." & i & "." & _
                    j & "." & k & "." _
                    & l & ". named " & .Name & _
                    " has " & _
                    .Files.Count & _
                    " files."
                    Debug.Print strL   
                  End With 'l
                Next l 
              End With 'k
            Next k
          End With 'j
        Next j
      End With 'i
    Next i
  End With 'h
End Sub							

Click Method 1 for first method.

Click Method 2 for second method.

Click Method 4 for fourth method.

Method 1, 2 and 3 Output will be identical and is shown below.

Folder 0. named C:\Documents and Settings\rdahl\
My Documents\My Web Sites\AutomationInformation has 4 files.
  Folder 0.0. named Favorites has 12 files.
  Folder 0.1. named images has 11 files.
    Folder 0.1.0. named SteveDahl has 0 files.
  Folder 0.2. named Programming has 2 files.
    Folder 0.2.0. named Java has 1 files.
    Folder 0.2.1. named MicrosoftExcel has 1 files.
    Folder 0.2.2. named MicrosoftExpressionWeb has 2 files.
      Folder 0.2.2.0. named Images has 4 files.
      Folder 0.2.2.1. named Pages has 5 files.
      Folder 0.2.2.2. named Text has 22 files.
        Folder 0.2.2.2.0. named NavigationNodes has 5 files.
        Folder 0.2.2.2.1. named Tables has 27 files.
    Folder 0.2.3. named MicrosoftMSDN has 1 files.
    Folder 0.2.4. named MicrosoftOffice has 1 files.
    Folder 0.2.5. named MicrosoftOutlook has 1 files.
    Folder 0.2.6. named MicrosoftVBA has 3 files.
      Folder 0.2.6.0. named CommandBars has 9 files.
      Folder 0.2.6.1. named Favorites has 2 files.
      Folder 0.2.6.2. named General has 9 files.
      Folder 0.2.6.3. named Images has 5 files.
      Folder 0.2.6.4. named UserForms has 8 files.
      Folder 0.2.6.5. named VBIDE has 11 files.
      Folder 0.2.7. named MicrosoftWindows has 1 files.
      Folder 0.2.8. named MicrosoftWord has 1 files.
      Folder 0.2.9. named Printing has 1 files.
      Folder 0.2.10. named SQL has 1 files.

Method 1

Method 2

Method 4

 

Valid XHTML 1.0 Transitional        Valid CSS!

c