Search for a file with a Wildcard

Using VBScript

I have a script that loops through a folder and gets the one with last modified date which works great.  I need to add some functionality to it and I am not sure how.

This is what I currently am using


Set fo = CreateObject("scripting.filesystemobject")
Set fl = fo.GetFolder("C:\MyFolder")
For Each f In fl.Files

    If f.DateLastModified > maxDt Then
        maxDt = f.DateLastModified
        Set myFile = f
    End If
Next

Lets say I have the following files in that Folder:
Bob_322.txt
Bob_328.txt
Joe_329.txt
Joe_325.txt

So in this example the Joe_329.txt has the last modified date, but say I want to get the last modified "Bob" file.  I am not sure how to incorporate a wildcard search with my current script.
LVL 3
99TimesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SweatCoderCommented:
Set fo = CreateObject("scripting.filesystemobject")
Set fl = fo.GetFolder("C:\MyFolder")
For Each f In fl.Files
    IF INSTR(1,f.Filename,"Bob") THEN
       If f.DateLastModified > maxDt Then
           maxDt = f.DateLastModified
           Set myFile = f
       End If
    END IF
Next

my example is hardcoded, but you'd probably want to create a function, and pass in the "Bob" string or whatever.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
99TimesAuthor Commented:
awesome. Thanks.
SweatCoderCommented:
you got it, 99.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.