regular expression to indicate a number

M

muyBN

How would I use a regular expression to return a file with any number (in
place of [num]) in the following code?

strFile = Dir(strPath & "*listings*[num]*.csv")
 
J

Jean-Guy Marcil

muyBN was telling us:
muyBN nous racontait que :
How would I use a regular expression to return a file with any number
(in place of [num]) in the following code?

strFile = Dir(strPath & "*listings*[num]*.csv")

I do not believe that you can use regular expressions with the Dir Function.
Basically, Dir allows a file name string that corresponds to what would be
allowed if you were using the DOS command line. This is why it allows * and
?.

In this case, since Dir usually handles files in alphabetical order, any
file with a digit in its fourth position would be handled before any files
not having a digit in its fourth positing. Knowing this, you could use code
like this to determine if such a file is present in the target folder:

'_______________________________________
Dim strFile As String
Dim strPath As String

strPath = "C:\Test\"

strFile = Dir(strPath & "Doc?*.doc")

If Not Mid(strFile, 4, 1) Like "#" Then
MsgBox "There are no files whose fourth digit is a number " _
& "in the """ & strPath & """ folder.", vbCritical
Else
MsgBox "Found one: """ & strFile & """!", vbExclamation
End If
'_______________________________________

But, if the digit position is unknown before hand, and especially if there
can be digits before the target position (* includes digits as well as
letters), I am not sure you can achieve what you want.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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