Page 1 of 1

Best way to check if a script is ran today?

Posted: 27 Oct 2022, 02:39
by william_ahk
I want a script to run only once per day. Right now I'm checking it by saving today's date into a text file. But I wonder if there's any low-level way, like is there a record in the system logging the last accessed date of a file or something like that? :think:

Code: Select all

WasIRan() {
	static save_filepath := A_ScriptDir "\" A_ScriptName ".last_run"
	FileRead last_run, % save_filepath
	FormatTime this_run, , yyyyMMdd
	if (last_run != this_run) {
		FileDelete % save_filepath
		FileAppend % this_run, % save_filepath
		return true
	}
}

Re: Best way to check if a script is ran today?  Topic is solved

Posted: 27 Oct 2022, 02:50
by boiler

Re: Best way to check if a script is ran today?

Posted: 27 Oct 2022, 03:29
by AHKStudent
boiler wrote:
27 Oct 2022, 02:50
Use FileSetTime and FileGetTime.
was looking for this too, thank you

Re: Best way to check if a script is ran today?

Posted: 27 Oct 2022, 07:39
by william_ahk
@boiler Thanks! :thumbup: Haven't thought of this way.