Burgaud Posted April 29, 2021 Share Posted April 29, 2021 (edited) 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! 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 April 29, 2021 by Burgaud Link to comment Share on other sites More sharing options...
JockoDundee Posted April 29, 2021 Share Posted April 29, 2021 Why are you not checking for return value of FileDelete? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted April 29, 2021 Share Posted April 29, 2021 5 hours ago, Burgaud said: I have two of this script running Use _Singleton () to ensure only one script is running at a single time. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Burgaud Posted May 1, 2021 Author Share Posted May 1, 2021 (edited) 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 May 1, 2021 by Burgaud Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 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 More sharing options...
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