Thanks guitarzan & jges for your responses.
I have tried both these methods and have ran into problems with both.
I'll go over guitarzan's first:
I have changed my code as you have advised using the Left() and Right() function. However when i run the code it does not find any file! And just returns, "No file exists".
Here is how I have modified my code, it could be a simple mistake I've made, however I cant seem to find any myself!
* Note: The file I am Searching for is:
ap_invtrans_CM_del.20120502.060004.723000.20120427.060024.083000.result
Code:
Const startDir = "C:\Program Files\SFTPPlus\inbox\testAccount_sftp_get"
Set oFSO = CreateObject("Scripting.FileSystemObject")
DateToday = Year(Date()) & Right("0" & Month(Date()), 2) & Right("0" & Day(Date()), 2)
sFileNameStart = "ap_invtrans_CM_del." & DateToday
sFileNameEnd = ".result"
Set objEmail = CreateObject("CDO.Message")
Set oFolder = oFSO.GetFolder(startDir)
Recurse(oFolder)
sendEmail(sFileName)
Sub Recurse(oFldr)
If IsAccessible(oFolder) Then
For Each oSubFolder In oFldr.SubFolders
Recurse oSubFolder
Next
For Each oFile In oFldr.Files
If Left(LCase(oFile.Name), Len(sFileNameStart)) = LCase(sFileNameStart) And _
Right(LCase(oFile.Name), Len(sFileNameEnd)) = LCase(sFileNameEnd) Then
sFullFileName = oFile.Name
WScript.Echo sFullFileName, "exists."
else
WScript.Echo "No File Exists."
WScript.Quit
End if
Next
End If
End Sub
Function IsAccessible(oFolder)
On Error Resume Next
IsAccessible = (oFolder.SubFolders.Count >= 0)
End Function
Sub sendEmail(oFile)
objEmail.From = "From E-mail"
objEmail.To = "My E-mail"
objEmail.Subject = "Some Subject"
objEmail.Textbody = "Some Text."
objEmail.AddAttachment "C:\Program Files\SFTPPlus\inbox\testAccount_sftp_get\"& sFullFileName
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "SMTP Server"
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
jges I have tired your solution also, although I do find it harder to understand. Also thank you for your added info regarding the dates, it proved very useful.
With your solution it seem to find the file just fine, however I get an error when it tries to add it as an attachment! Here my code for your solution.
* Note: The file I am Searching for is:
ap_invtrans_CM_del.20120502.060004.723000.20120427.060024.083000.result
Code:
set re = new regexp
dim strInput
DateToday = Year(Date()) & Right("0" & Month(Date()), 2) & Right("0" & Day(Date()), 2)
strInput = "ap_invtrans_CM_del." & DateToday & ".result"
re.Pattern = "^ap_invtrans_CM_del\." & DateToday & ".*\.result"
re.IgnoreCase = true
re.Global = true
Set objEmail = CreateObject("CDO.Message")
Set Matches = re.Execute(strInput)
wscript.echo("Matches.Count: " &Matches.Count)
if Matches.Count >= 1 then
value1 = Matches.Item(0)
else
wscript.echo("No matches found")
end if
wscript.echo(value1)
sendEmail(sFileName)
Sub sendEmail(oFile)
objEmail.From = "From E-mail"
objEmail.To = "My E-mail"
objEmail.Subject = "Some Subject"
objEmail.Textbody = "Some Text."
objEmail.AddAttachment "C:\Program Files\SFTPPlus\inbox\testAccount_sftp_get\"& value1
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "SMTP Server"
objEmail.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
Thanks to both of you again