computing
  • 1

Batch Count No Of Folders

  • 1

Hi,

I have been googling for a batch file that can be used to count the number of folders in a given location, for example “h:\”. So far all i can seem to find it ways of counting files but not folders.

Is it possible to count folders? i only need to count root folders and not sub folder, can someone please help?

Thanks,

Share

1 Answer

  1. Hi nbrane, thats for your time, however the code you have given will only count files and not folders (directories). Here is a solution for those who are interested…..This will count all the root folders (not sub or files) in a given path..

    Private Sub Command1_Click()
    ListDirectories
    End Sub

    Sub ListDirectories()

    Dim folName As String
    Dim folPath As String
    Dim folCounter As Integer
    folCouunter = 0

    folPath = “J:”

    folName = Dir(folPath, vbDirectory)

    Do Until Len(folName) = 0

    If GetAttr(folPath & folName) = vbDirectory Then
    folCounter = folCounter + 1
    End If

    folName = Dir
    Loop

    MsgBox folCounter
    End Sub

    • 0