|
-
Jul 4th, 2003, 10:52 AM
#1
Thread Starter
New Member
VB Script
Hi All,
I am attempting to create a small vbscript program that will check a directory to see if it has a file with todays date in it. Then the script will send an e-mail out if there isn't.
Here is the code I have so far
On Error Resume Next
Dim strPath
Dim blnFound
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = Dir(pstrDir & "\*.*")
While Len(strPath) > 0 And Not blnFound
If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
blnFound = True
End If
strPath = Dir()
Wend
CheckForTodaysFile = blnFound
If CheckForTodaysFile("M:\monitor\edi\edi\dump") Then
Set refOutlook=CreateObject("outlook.application")
sendmail=1
If err <> 0 Then
sendmail=0
End If
On Error GoTo 0
' do usefull stuff
emaildata=("The Releases have not been loaded today. Please check
their status and resolve!")
If sendmail=1 Then
Set refmailitem=refoutlook.createitem(0)
refmailitem.to="[email protected]"
refmailitem.Subject="New Realeses have not been loaded.Please
Check!!"
refmailitem.body=emaildata
refmailitem.send
Set refmailitem=nothing
Set refoutlook = Nothing
End If
End If
But it is not working. Can someone take a look and see if I am missing something.
Thanks for any help...
-
Jul 4th, 2003, 12:04 PM
#2
Fanatic Member
Just so you know next time put your code using (vbcode) and then paste your code and close it with (/vbcode) but use brackets instead of perenthesis.
VB Code:
On Error Resume Next
'the searching part of your code works fine.
Dim strPath
Dim blnFound
pstrDir = "C:\"
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = Dir(pstrDir & "\*.*")
While Len(strPath) > 0 And Not blnFound
If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
blnFound = True
End If
strPath = Dir()
Wend
'Now what are you doing here? Why are you giving
'CheckForTodaysFile the blnFound value?
CheckForTodaysFile = blnFound
'Then when you use your if statment it seems like you are
'calling the function CheckForTodaysFile with a string
'parameter. What does CheckForTodaysFile do?
If CheckForTodaysFile("M:\monitor\edi\edi\dump") Then
Set refoutlook = CreateObject("outlook.application")
sendmail = 1
If Err <> 0 Then
sendmail = 0
End If
On Error GoTo 0
' do usefull stuff
emaildata = ("The Releases have not been loaded today. Please check their status and resolve!")
If sendmail = 1 Then
Set refmailitem = refoutlook.createitem(0)
'I was using my email here to be testing it.
refmailitem.Subject = "New Realeses have not been loaded.Please Check!!"
refmailitem.body = emaildata
refmailitem.send
Set refmailitem = Nothing
Set refoutlook = Nothing
End If
End If
Everything in your code works fine except what is CheckForTodaysFile? Is it a function or a variable? If it is a function please post your code for it otherwise I can't help since that is where your code is messing up.
-
Jul 4th, 2003, 01:55 PM
#3
Thread Starter
New Member
Hi Maldrid,
Thanks for your reply....
Originally the first part of the code was called "checkfortodaysfile" as a function.
All I want, is for the e-mail to be sent out if there is not a file in the directory with todays date.
I need the program to search the "M:\monitor\edi\edi\dump" folder, and then if it doesn't find the file, to send the e-mail.
Now I know the e-mail part of the code works fine. So how do I link the two parts of the code together?
Thanks.....
-
Jul 7th, 2003, 01:20 PM
#4
Fanatic Member
Ok here is what your code should look like.
VB Code:
Dim strPath As String
Dim blnFound as Boolean
pstrDir = "M:\monitor\edi\edi\dump"
'not sure what fso is used for?
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = Dir(pstrDir & "\*.*")
While Len(strPath) > 0 And Not blnFound
If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
blnFound = True
End If
strPath = Dir()
Wend
If blnFound Then
Set refoutlook = CreateObject("outlook.application")
sendmail = 1
If Err <> 0 Then
sendmail = 0
End If
On Error GoTo 0
' do usefull stuff
emaildata = ("The Releases have not been loaded today. Please check their status and resolve!")
If sendmail = 1 Then
Set refmailitem = refoutlook.createitem(0)
'I was using my email here to be testing it.
refmailitem.Subject = "New Realeses have not been loaded.Please Check!!"
refmailitem.body = emaildata
refmailitem.send
Set refmailitem = Nothing
Set refoutlook = Nothing
End If
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|