Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 749
  • Last Modified:

VBScript Wildcard solution needed - file.extension

This question refers to VBScript only.  Is there a clean and simple function that can use to find wildcards in a file extensions?  

For example, I am looking for file in a dir called, c:\temp\. Within the dir there are many files which have the same name but the extestions are not unique. They are based on "todays" date AND time (tempfile.2007080206121).  

What I would like to find is a solution that will msgbox "found" if it can find a file from today no matter the time. So, it will look for tempfile.2007020206, but don't care for the time.

Thanks!



The following didn't really help and/or the solution was just too long.
http://www.tek-tips.com/viewthread.cfm?qid=726674
http://www.source-code.biz/snippets/vbscript/1.htm
http://64.233.169.104/search?q=cache:HVoUTsj1ZroJ:www.experts-exchange.com/Web_Development/Miscellaneous/Q_20912792.html+filename+wildcard+vbs+-ntfs&hl=en&ct=clnk&cd=3&gl=us
0
onebulgar
Asked:
onebulgar
  • 3
  • 2
1 Solution
 
RobSampsonCommented:
Hi, try this:
'=============
strSourceFolder = "C:\Temp"
If Right(strSourceFolder, 1) = "\" Then strSourceFolder = Left(strSourceFolder, Len(strSourceFolder) - 1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strSourceFolder) = True Then
      strDate = Left(TimeNow(Now), 4) & Mid(TimeNow(Now), 6, 2) & Mid(TimeNow(Now), 9, 2)
      For Each objFile In objFSO.GetFolder(strSourceFolder).Files
            If Left(Mid(objFile.Name, InStrRev(objFile.Name, ".") + 1), 8) = strDate Then
                  MsgBox "Found: " & objFile.Name
            End If
      Next
Else
      MsgBox "The source folder " & strSourceFolder & " does not exist."
End If

Function TimeNow(dDateTime)
      TimeNow =      Year(Now) & "-" &_
                        Right("00" & Month(Now), 2) & "-" &_
                        Right("00" & Day(Now), 2) & "-" &_
                        Right("00" & Hour(Now), 2) & "-" &_
                        Right("00" & Minute(Now), 2) & "-" &_
                        Right("00" & Second(Now), 2)
End Function
'=============

Regards,

Rob.
0
 
onebulgarAuthor Commented:
It doesn't do anything. It runs, but not popup -nothing ;(

Also, I just double checked the file format and it is temp1-2007-07-28.txt.2007072802541

Would this be the problem?
0
 
RobSampsonCommented:
No, that shouldn't be a problem, it just checks the last part after the last full stop.  Are you sure you have a file from today?  Underneath this line:
strDate = Left(TimeNow(Now), 4) & Mid(TimeNow(Now), 6, 2) & Mid(TimeNow(Now), 9, 2)

place
MsgBox strDate

and you will see the date that it is looking for.  Check that you have a file with that date in the last segment of your filename.

Regards,

Rob.
0
 
onebulgarAuthor Commented:
You know, you are right. I just checked it and it works? I am not sure what I did last time.

You got the points but can I ask for an additional help? Can we verify that the search string 'strDate' AND the actual file.datemodified match before msgbox it?

Thanks a million!
0
 
RobSampsonCommented:
OK, so you want to check the actual DateModified value of the file, instead of the date written in the extension?

Sure, then change this line:
If Left(Mid(objFile.Name, InStrRev(objFile.Name, ".") + 1), 8) = strDate Then

to this:
If Year(objFile.DateLastModified) & Right("00" & Month(objFile.DateLastModified), 2) & Right("00" & Day(objFile.DateLastModified), 2) = strDate Then

and it will MsgBox only for files that have been modified today, and won't look at their extension at all.....
I think that's what you were asking....

Regards,

Rob.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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