• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

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.
0
99Times
Asked:
99Times
  • 2
1 Solution
 
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.
0
 
99TimesAuthor Commented:
awesome. Thanks.
0
 
SweatCoderCommented:
you got it, 99.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now