Jump to content

problem with Filegettime, filedelete... or is this something else?


Recommended Posts

This is my script in question:

func _LogMessage($text="", $key="")
    local static $logfile = @MyDocumentsDir & '\' & StringTrimRight(@ScriptName,4) & '.log'
;   if FileGetTime($logfile, 1, 1) < StringFormat("%04s%02s%02s000000", @YEAR, @MON, @MDAY) then    ;if logfile is older than today
;       FileDelete($logfile)
;   endif
    FileWrite($logfile, stringFormat("%s [%1s] %s\r\n", _NowCalc(), $key, $text))
endfunc

_LogMessage( FileGetTime(@MyDocumentsDir & '\' & StringTrimRight(@ScriptName,4) & '.log', 0, 1) )
_LogMessage( FileGetTime(@MyDocumentsDir & '\' & StringTrimRight(@ScriptName,4) & '.log', 1, 1) )
_LogMessage( FileGetTime(@MyDocumentsDir & '\' & StringTrimRight(@ScriptName,4) & '.log', 2, 1) )

File @MyDocumentsDir & '\' & StringTrimRight(@ScriptName,4) & '.log' was created several days ago:

2021/04/29 15:04:50 [ 20210429150450
2021/04/29 15:04:50 [ 20210427115800
2021/04/29 15:04:50 [ 20210429150450
 

 

Seems OK. So I went and uncommented the file If then statement in the _LogMessage() function.
The purpose of that set of instruction is to delete the logfile if it is older than today.

YET when I executed the script without the comments, the function kept deleting the file every single time.

Even when I manually deleted the log file, the script still kept on deleting the log file. and still recognizes that said logfile was created several days ago.

In fact, these were printed AFTER the log file was manually deleted.

2021/04/29 15:04:50 [ 20210429150450
2021/04/29 15:04:50 [ 20210427115800
2021/04/29 15:04:50 [ 20210429150450


Umm... what gives?

I am stuck!

image.png.823a8f81acd32bb9d759fe4338c40561.png

Dan


PS: I have two of this script running. Is it because the file is still OPEN in the other scripts thus not allowing to close / create a new file with a newer date?

 

 

 

Edited by Burgaud
Link to comment
Share on other sites

I had bad experience/weird results using _singleton and decided not to use it. And I could not use _singleton to query existence of others without taking the spot first.

ie: it is like biting the pie before asking

I need something that queries first. So I went instead query existence of GUIs using

if WinGetProcess("WatchDog:Main") < 0 then              ;there is no WatchDog:Main, perform WatchDog:Main
        _WatchDogMain()
    elseif WinGetProcess("WatchDog:Secondary") < 0 then     ;there is no WatchDog:Secondary, perform WatchDog:Secondary
        _WatchDogSecondary()
    endif

Basically, the said single script has 2 main functions:

1. WatchDogMain monitors WatchDogSecondary. if WatchDogSecondary is not running, it shellexecutes it. Loop

2. WatchDogSecondary monitors WatchDogMain. If WatchDogMain is not running, it shellexecutes it. AND also performs other tasks... Loop.

This ensures both are running on the computer.

 

Quote

Why are you not checking for return value of FileDelete?

What will checking for FileDelete error do? The file DID get wiped/emptied out. But the creation date of the new file is still OLD is what bothers me.

Edited by Burgaud
Link to comment
Share on other sites

6 minutes ago, Burgaud said:

What will checking for FileDelete error do?

Call it a stupid rule-of-thumb of mine, but if I’m having  problems with a File being deleted or not, I’ll check the return code of the FileDelete() command.
It’s crazy, I know.

Also, when you say

On 4/29/2021 at 12:19 AM, Burgaud said:

Seems OK. So I went and uncommented the file If then statement in the _LogMessage() function.
The purpose of that set of instruction is to delete the logfile if it is older than today.

YET when I executed the script without the comments, the function kept deleting the file every single time.

Even when I manually deleted the log file, the script still kept on deleting the log file. and still recognizes that said logfile was created several days ago.

In fact, these were printed AFTER the log file was manually deleted.

what do you mean? the log file was there even though you deleted it?

what if you deleted and created the file manually, totally outside of autoit, and then look in file explorer, what does it say?

Code hard, but don’t hard code...

Link to comment
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
 Share

  • Recently Browsing   0 members

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