• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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