Sign in to follow this  
Followers 0
big_daddy

Comparing system time with time stamp of file

12 posts in this topic

How can I compare the time stamp of a file with the current system time. What I'm trying to accomplish with this is to have the script wait for a program to updates a certain file, and when it does I want it to carry out the next function. So if the time stamp is within 10 minutes of the current system time then it will continue, if not then it will wait until it is.

Share this post


Link to post
Share on other sites



You can do FileReadLine() or put the time stamp in a specific location in an .ini and do an IniRead().


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This should work well for you:

#Include <Date.au3>

; Get the last-modified time of the file
Local $FGT = FileGetTime('C:\AutoExec.bat')
; Convert that to a format expected by _DateDiff()
Local $FileDateAsString = $FGT[0] & '/' & $FGT[1] & '/' & $FGT[2] & ' ' & $FGT[3] & ':' & $FGT[4] & ':' & $FGT[5]
; Determine the number of seconds since the last-modified time
Local $Age = _DateDiff('s', $FileDateAsString, _NowCalc())

; Wait until the file is ten minutes old if necessary
If $Age < (10 * 60) Then
    Local $TimeToSleep = ((10 * 60) - $Age) * 1000
    Sleep($TimeToSleep)
EndIf

; Do the rest
; ...

P.S. I like your avatar!

Share this post


Link to post
Share on other sites

That's exactly what I was looking for!!!

This is what I have so far:

#Include <Date.au3>
    $x = @DesktopWidth/2
    $y = @DesktopHeight/2
         ToolTip("Please Wait...", $x, $y, "Audit in progress")
    Do
    ; Get the last-modified time of the file
        Local $FGT = FileGetTime('C:\TrackitAudit.id')
    ; Convert that to a format expected by _DateDiff()
        Local $FileDateAsString = $FGT[0] & '/' & $FGT[1] & '/' & $FGT[2] & ' ' & $FGT[3] & ':' & $FGT[4] & ':' & $FGT[5]
    ; Determine the number of seconds since the last-modified time
        Local $Age = _DateDiff('s', $FileDateAsString, _NowCalc())
    ;Wait until the file is less than 1 minute old      
        Sleep(2000)
        Until $Age < (60)

How can I keep the tooltip visible from before the Do statement until after it gives a true value?

P.S. Thanks I made it in Ulead Cool 3D Studio here a while back.

Share this post


Link to post
Share on other sites

Okay, let me explain this a little better.

$x = @DesktopWidth/2

$y = @DesktopHeight/2

ToolTip("Please Wait...", $x, $y, "Audit in progress")

;This is where I want the tooltip to start of course

Do

; Get the last-modified time of the file

Local $FGT = FileGetTime('C:\TrackitAudit.id')

; Convert that to a format expected by _DateDiff()

Local $FileDateAsString = $FGT[0] & '/' & $FGT[1] & '/' & $FGT[2] & ' ' & $FGT[3] & ':' & $FGT[4] & ':' & $FGT[5]

; Determine the number of seconds since the last-modified time

Local $Age = _DateDiff('s', $FileDateAsString, _NowCalc())

;Wait until the file is less than 1 minute old

Sleep(2000)

Until $Age < (60)

;This is where I want it to end

WinClose("Track-It! Audit")

Exit

Hopefully this helps clear things up a little.

Share this post


Link to post
Share on other sites

Put the ToolTip 'start' inside the Do loop, that way it refreshes every loop, it will stop automatically after the loop has ended.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This should work well for you:

#Include <Date.au3>

; Get the last-modified time of the file
Local $FGT = FileGetTime('C:\AutoExec.bat')
; Convert that to a format expected by _DateDiff()
Local $FileDateAsString = $FGT[0] & '/' & $FGT[1] & '/' & $FGT[2] & ' ' & $FGT[3] & ':' & $FGT[4] & ':' & $FGT[5]
; Determine the number of seconds since the last-modified time
Local $Age = _DateDiff('s', $FileDateAsString, _NowCalc())

; Wait until the file is ten minutes old if necessary
If $Age < (10 * 60) Then
    Local $TimeToSleep = ((10 * 60) - $Age) * 1000
    Sleep($TimeToSleep)
EndIf

; Do the rest
; ...

P.S. I like your avatar!

nice looking code alex (as usual) but possibly a little overkill?

While 1
$blah = Number(FileGetTime(@ScriptFullPath,2,1))
$blah2 = Number(@YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC)
If $blah2 - $blah < 1000 Then
    MsgBox(0,"Ding","Your file is less than 10 minutes old"
    Exit
EndIf
WEnd

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

nice looking code alex (as usual) but possibly a little overkill?

While 1
$blah = Number(FileGetTime(@ScriptFullPath,2,1))
$blah2 = Number(@YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC)
If $blah2 - $blah < 1000 Then
    MsgBox(0,"Ding","Your file is less than 10 minutes old"
    Exit
EndIf
WEnd
This isn't gonna work...

assume filedatetime: 20051220125500

assume currdatetime: 20051220130000

diff = 4500 but only 5 minutes....

The _DateDiff() function works better ... :P

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This isn't gonna work...

assume filedatetime: 20051220125500

assume currdatetime: 20051220130000

diff = 4500 but only 5 minutes....

The _DateDiff() function works better ... :P

ah... yet another good argument for trying more than current data. back to the corner for me...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Put the ToolTip 'start' inside the Do loop, that way it refreshes every loop, it will stop automatically after the loop has ended.

Well that works, but it sits there and flickers each time it loops. I guess it's not that big of a deal though.

Share this post


Link to post
Share on other sites

Have you considered using SplashTextOn()? --

#Include <Date.au3>

SplashTextOn('Audit in progress', @LF & 'Please wait...', 144, 64)
Do
; Get the last-modified time of the file
    Local $FGT = FileGetTime('C:\TrackitAudit.id')
; Convert that to a format expected by _DateDiff()
    Local $FileDateAsString = $FGT[0] & '/' & $FGT[1] & '/' & $FGT[2] & ' ' & $FGT[3] & ':' & $FGT[4] & ':' & $FGT[5]
; Determine the number of seconds since the last-modified time
    Local $Age = _DateDiff('s', $FileDateAsString, _NowCalc())
; Wait until the file is less than 1 minute old     
    If $Age > 60 Then Sleep(2000)
Until $Age < 60
SplashOff()

Share this post


Link to post
Share on other sites

Thank you all for all the help! I think the script is ready for deployment.

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