1.

Solve : adding to a script to send an email if a folders date modified is > 1 day?

Answer» HI guys,

using the script below i am successfully able to find if a folders date modified time is less than 1 day ignore it and if not, do an else command to create a TEXT file in a location.

what i need is to instead of create a text file, i need it to send an email to inform me it is greater than 1 day.

this is the current script;

dim filesys, filetxt, getname, path
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.GetFolder("c:\test").DateLastModified >= Date - 1 Then
Wscript.quit
   Else if   objFSO.GetFolder("c:\test").DateLastModified <= Date - 1 Then
      Set filesys = CreateObject("Scripting.FileSystemObject")
      Set filetxt = filesys.CreateTextFile("c:\test\not created.txt", True)
      path = filesys.GetAbsolutePathName("c:\test\not created.txt")
      getname = filesys.GetFileName(path)
      filetxt.WriteLine("file doesnt exist.")
      filetxt.Close
   End if
end if

im using outlook 2013 and windows 7.

thanks!Is that code complete?

You can use a batch file to send an email using VBS,  and also use batch code to check if the folder date is not todays date
 - that's all your code seems to be doing (although the Date variable appears undefined).

I'm not sure how you are launching this - more info is needed. Quote from: foxidrive on January 22, 2015, 11:18:13 AM
the Date variable appears undefined

Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings. On my system wscript.echo Date produces 22/01/2015, and adding or subtracting numbers e.g. Date-1, Date+30 produces a similarly formatted date string, representing the date that number of days in the past or future.

Note to the OP: you mention files less than 1 day old, and files more than 1 day old. What do you want to do with files that are exactly ONE day old?






This is how you could try to send an email using Outlook. I only have Outlook 2003 so I don't know if it would work with Outlook 2013. You would probably need to change Outlook security settings to allow unattended scripted sending of emails.

Code: [Select]ToAddress = "[email PROTECTED]"
MessageSubject = "Subject goes here"
MessageBody = "Body message goes here."
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Send

There are better ways of sending emails, like the CDO object.
Quote from: Salmon Trout on January 22, 2015, 12:57:05 PM
Date is a built-in VBscript function which returns the current system date, formatted according to the system locale settings.

Thanks Mr Trout.  You're very helpful to an old codger.

I did search the WSH help for 'date' and clicked on the few that looked likely suspects, but gave up too soon it looks like.

Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch. Quote from: Squashman on January 22, 2015, 07:59:01 PM
Foxidrive. Look at SS64 website. It has a list of all the VBscript commands just like it does for NT batch.

Thanks Squashman.


Discussion

No Comment Found