Question : count # of files in folder given a partial name

I have folders named:
AV-215 The Best Is Yet To Come
AV-300 For The One Time You Do It
AV-215 Kinda Liked You Before
AV-310 This Is The Place And The Time
...etc.
I need a way to input, for example "AV-215" and have my VB6 program tell me how many files in ALL folders with the first characters "AV-215", total.

Answer : count # of files in folder given a partial name

OK, now it looks through the subfolders.

Be sure to pass a wild card in NameFragment, as I indicated in my first comment.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Function CountFiles(Directory As String, NameFragment As String)
 
    Dim fso As Object, fld As Object, sf As Object, fil As Object
    Dim Count As Long
 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(Directory)
 
    ' Remove if you do not want to check the directory itself
    For Each fil In fld.Files
        If LCase(fil.Name) Like LCase(NameFragment) Then Count = Count + 1
    Next
 
    For Each sf In fld.SubFolders
        For Each fil In sf.Files
            If LCase(fil.Name) Like LCase(NameFragment) Then Count = Count + 1
        Next
    Next
 
    CountFiles = Count
 
    Set fil = Nothing
    Set sf = Nothing
    Set fld = Nothing
    Set fso = Nothing
 
End Function
Random Solutions  
 
programming4us programming4us