Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBSCRIPT Wildcard Characters not working

Status
Not open for further replies.

cdcodeman

MIS
Dec 10, 2010
1
US
I am creating a script to find a certain file and execute a set of commands running on Windows Server Standard SP2. I have used wildcards "?" for the time stamp in the past. The problem is that I am having problems calling the "?". Here is the code I have so far:

Option Explicit


'Date Function Declared
Function padDate(intNumber)
if intNumber <= 9 Then
padDate = "0" & CStr(intNumber)
Else
padDate = CStr(intNumber)
End If
End Function

Dim strDate

'Variable Proc for the date
strDate = Year(Date) & padDate(Month(Date)) & padDate(Day(Date))
'Set Dimension
DIM fso

'Set Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Create Condition
If (fso.FileExists("\\Server\StartOfFileName"_
& strDate & "??????_Report1.txt")) Then

'Alert User
WScript.Echo("File exists!")
WScript.Quit()
Else
'Alert User
WScript.Echo("File does not exist!")
End If

'Exit Script
WScript.Quit()

I need to find a way to get the ?????? to pose as characters no matter what. I have thought about trying a loop between 0000001 and 235959, but I thought that would take a bit.

Is there another way to declare variables within Windows?
 
To my knowledge there's only 2 ways to use wildcards in VBScript. 1) Use a regular expression, or 2) use an external command via "objShell.Run" or "objShell.Exec". Outside of those possibilities you have to parse the data and look for the key information. Here's my take on your script...

Code:
Option Explicit

' Declare Vars
Dim strDate, objFSO, strPath, strFilePrefix, strFileSuffix, objFolder, objFile
Dim arrFileNameParts

'Variable Proc for the date
strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)

'Set Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

strPath = "\\Server\Share\"
strFilePrefix = "StartOfFileName" & strDate
strFileSuffix = "_Report1.txt"

[green]' Get handle to root folder[/green]
Set objFolder = objFSO.GetFolder(strPath)

[green]' Go through each file in the folder[/green]
For Each objFile In objFolder.Files
    [green]' Examine file further if suffix is present[/green]
    If InStr(objFile.Name, strFileSuffix) Then
        [green]' Break file name in half[/green]
        arrFileNameParts = Split(objFile.Name, "_")

        [green]' Examine 6 characters on the right side of the first half of the file name[/green]
        If IsNumeric(Right(arrFileNameParts(0), 6)) Then
            WScript.Echo "Found Report: " & objFile.Name
        Else
            WScript.Echo "Not the one."
        End If
    End If
Next

Notice that I extract what I expect to be a numeric string and then test it?

PSC
[&mdash;] CCNP (R&S/Wireless) [&bull;] CCSP [&bull;] MCITP: Enterprise Admin [&bull;] MCSE [&mdash;]

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top