0
votes

Is there a way of storing the directory found when using a wildcard? For example, if I have code that checks whether a directory exists:

Public Function DirectoryFinder(PartialFolderName As String)
     Dim FilePath As String
     If Dir(CurrentProject.Path & "\DataFolder\" & PartialFolderName & "*", vbDirectory)<>"" Then
          'FilePath = ???
     End If
End Function

Where the current project resides in C:\Folder and the desired full filepath is C:\Folder\DataFolder\PartialFolderName12345.

Is there a way to capture the directory found by the Dir() function within the FilePath variable? If I define FilePath as the following, I don't believe it captures the directory found:

FilePath=CurrentProject.Path & "\DataFolder\" & PartialFolderName & "*"

Rather, it sets FilePath equal to the string "C:\Folder\DataFolder\PartialFolderName*", which doesn't work for what I need.

What I want to be able to capture is the full "C:\Folder\DataFolder\PartialFolderName12345"