We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Search for a file with a Wildcard

99Times
99Times asked
on
Medium Priority
293 Views
Last Modified: 2012-05-05
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.
Comment
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
awesome. Thanks.
you got it, 99.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.