We help IT Professionals succeed at work.
Get Started

VB Script: check if files exist and datemodified is equal of today if not send a notification e-mail

Luis Diaz
Luis Diaz asked
on
411 Views
Last Modified: 2015-02-27
Hello experts,

I have three files with the following names:
m.csv, tt.csv, and sp.csv

Those files are generated on daily basis in C:\test and moved to an archive folder.

I need a VB Script which to do the following:

1-Check if the files exist in C:\test (Be careful, the loop cannot be by count>0 as We have other files in C:\test
2-Check if the date modified of the files is equal of today.
3-If one of those conditions is not met:
The script need to run the following notification code (I want a unique .vbs (loops+notification)


' Send by connecting to port 25 of the SMTP server.
Dim iMsg 
Dim iConf 
Dim Flds 
Dim strHTML

Const cdoSendUsingPort = 2

set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields


' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    'ToDo: Enter name or IP address of remote SMTP server.
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Update
End With

' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<p>-----This message has been sent automatically-----<p>"
strHTML = strHTML & "Hello,</br><p>Csv files haven't been generated today,</b> please check the interface.</p>"
strHTML = strHTML & "<p>Regards,</p>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"

' Apply the settings to the message.
With iMsg
    Set .Configuration = iConf
    .To = "" 'ToDo: Enter a valid email address.
    .From = "" 'ToDo: Enter a valid email address.
    .Subject = "[WARNING] Csv files for CC  haven't been generated today"
    .HTMLBody = strHTML
    .AddAttachment "C:\test\log-files-checks.txt"
    .Send
End With

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

WScript.Quit

Open in new window


log requirements:
1-Log name: log-files-checks.txt
2-If the folder in which the script check the files don't exist log file should contains Now & "The folder" & variable doesn't exist
3-If one of the files m.csv, tt.csv, and sp.csv" doesn't exist log file file should contains Now & “ERROR”: ” & ": One of the following files "m.csv, tt.csv, and sp.csv" hasn't been found
4-If datemodified of one of the file is not equal of today Now & “ERROR” & “the following files : m.csv, tt.csv, and sp.csv" has a datemodified equal of today
4-If the notification is sent the log file should contain Now & "ERROR: Notification has been sent."
5-If the files are in the folder with a date modified of today the log file should contains Now “SUCESS: All is good files exist in the folder and the datemodified is equal of today notification hasn’t been sent”
Comment
Watch Question
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE