Sign in to follow this  
Followers 0
r0ssd

Script to check file date then send email

7 posts in this topic

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 email

For $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)

Next

I 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

Share this post


Link to post
Share on other sites



Hi r0ssd,

what you are looking for is FileGetTime() and _DateDiff(). With these two functions you can build what you want to do. :huh2:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

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

:huh2:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

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

:huh2:

Thanks Hannes, got it working now! ;)

Share this post


Link to post
Share on other sites

You're welcome :huh2:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Thanks Hannes, got it working now! :mellow:

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!

Share this post


Link to post
Share on other sites

Thanks Hannes, got it working now! :mellow:

Sorry. Never mind. I think I got it working. Thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0