Jump to content

Script to check file date then send email


Recommended Posts

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

Link to comment
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]
Link to comment
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! ;)
Link to comment
Share on other sites

  • 1 month later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...