r0ssd Posted June 21, 2011 Posted June 21, 2011 Hello, I am quite new to Autoit and what I am trying to do is slightly beyond me at the moment so hoping someone can help!Basically I want a script to check the last modified date of a file and if it is over 1 day then send an email alert.I have a similar script which I was trying to modify which will scan a file for a certain word then send an email alert.#include <INet.au3>$TextFileName = "file path"$s_SmtpServer = "email server"$s_FromName = "user name"$s_FromAddress = "user@email.com"$s_ToAddress = "user2@email.com"$s_Subject = "Subject"Dim $as_Body[2]$as_Body[0] = "Message text line 1"$as_Body[1] = "Message text line 2"; First we read the text file$Log = FileRead($TextFileName); Put the contents into an array$pageArray = StringSplit($Log, @CRLF); Now go through the array and look for the word failure if its found send and emailFor $i = 1 To $pageArray[0] If StringInStr($pageArray[$i], $findtext) Then $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @computername, -1)NextI know I will need to include date.au3 and use the FileGetTime function but I'm a bit stuck trying to combine everything.Any help greatly appreciated.Cheers
hannes08 Posted June 21, 2011 Posted June 21, 2011 Hi r0ssd, what you are looking for is FileGetTime() and _DateDiff(). With these two functions you can build what you want to do. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
hannes08 Posted June 21, 2011 Posted June 21, 2011 Well, this is not the most handsome solution, but it works: #Include <Date.au3> $t1 = FileGetTime("test.cmd", 0, 1) ConsoleWrite($t1 & @CRLF) $t2 = StringReplace(StringReplace(StringReplace(_DateAdd("D", -1, _NowCalc()),":", "")," ", ""), "/", "") If $t1 < $t2 Then ConsoleWrite( $t1 &" < "& $t2 & @CRLF) Else ConsoleWrite( $t1 &" > "& $t2 & @CRLF) EndIf Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
r0ssd Posted June 22, 2011 Author Posted June 22, 2011 Well, this is not the most handsome solution, but it works: #Include <Date.au3> $t1 = FileGetTime("test.cmd", 0, 1) ConsoleWrite($t1 & @CRLF) $t2 = StringReplace(StringReplace(StringReplace(_DateAdd("D", -1, _NowCalc()),":", "")," ", ""), "/", "") If $t1 < $t2 Then ConsoleWrite( $t1 &" < "& $t2 & @CRLF) Else ConsoleWrite( $t1 &" > "& $t2 & @CRLF) EndIf Thanks Hannes, got it working now!
hannes08 Posted June 22, 2011 Posted June 22, 2011 You're welcome Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
MrMMM Posted August 18, 2011 Posted August 18, 2011 Thanks Hannes, got it working now! r0ssd, could you please kindly paste the whole code you used to do it? I've been trying to do this exact thing with a .bat file for a while, but with no success. Thank you!
MrMMM Posted August 18, 2011 Posted August 18, 2011 Thanks Hannes, got it working now! Sorry. Never mind. I think I got it working. Thank you!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now