multiple file masks on dir$()

L

larrysulky

Hi. I searched but couldn't find an answer to or example of this. Is it
possible to specify multiple file masks on a single call to dir$()? I
have:

theFile = Dir$(TemplatePath & "*.bas")

but what I'd really like is something like:

theFile = Dir$(TemplatePath & "*.bas" | TemplatePath & "*.frm")

That is, the file mask should constrain to either *.bas or *.frm. Or
can I do something like

theFile = Dir$(TemplatePath & "*.bas") & Dir$(TemplatePath & "*.frm")

? It sure seems possible but the syntax is defeating me.

TIA
---larry
 
H

Helmut Weber

Hi Larry,
Is it possible to specify multiple file masks on a single call to dir$()?

not to my knowledge.

If you have or want to use dir,
for which there may be good reasons,
then I'd code my own filter.

Or use something rather primitive:

Dim sTmp As String
sTmp = Dir("c:\test\word\" & "*.xls")
If sTmp = "" Then
sTmp = Dir("c:\test\word\" & "*.txt")
End If
MsgBox sTmp

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Karl E. Peterson

Hi. I searched but couldn't find an answer to or example of this. Is
it possible to specify multiple file masks on a single call to
dir$()? I have:

theFile = Dir$(TemplatePath & "*.bas")

but what I'd really like is something like:

theFile = Dir$(TemplatePath & "*.bas" | TemplatePath & "*.frm")

Not directly, no. But I've coded up a class module that handles this pesky
detail, as well as recursive folder navigation, pretty neatly. See
http://vb.mvps.org/samples/DirDrill to give it a try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top