Find directory using wildcards

0

How do I find a folder as if it were a file?

For example, the code to find the TESTE.TXT file is:

b = dir("c:\minhapasta\t*.*xt")
msgbox b

But for folders the asterisk does not work. What alternative do we have?

    
asked by anonymous 01.05.2015 / 16:36

1 answer

1

You can (*) use the GetDirectories() method of the Directory class to get the path of directories that are in the c:\minhapasta\ directory and that match the search t*

Dim dirs As String() = Directory.GetDirectories("c:\minhapasta\", "t*", SearchOption.TopDirectoryOnly);  

If you want the search to extend to sub-directories, change the second parameter to SearchOption.AllDirectories .

You can then use a For Each to go through each of these directories and get the paths to *.txt

(*) In VB, I think VBA is the same.
Source: msdn     

01.05.2015 / 17:23