List certain files in folder (using Excel 2003)

84 Views Asked by At

I am listing all files that follow a certain pattern using this code:

Dim strFileName As String, strFileSpec As String
Dim FileList() As String
Dim intFoundFiles as Integer

strFileSpec = archivePath & PatID & "*.csv"
strFileName = Dir(strFileSpec)
Do While Len(strFileName) > 0
    ReDim Preserve FileList(intFoundFiles)
    FileList(intFoundFiles) = strFileName
    intFoundFiles = intFoundFiles + 1
    strFileName = Dir                     
Loop

it loads the files corresponding to the file spec into an array which works fine so far.

Problem:
If I have files like 101-20200120.csv the code finds also others like 10123-20200120.csv which also comply to the filter. However I need to list only those that have exactly 101 - not the others like 1012345.

How can I code that?

0

There are 0 best solutions below