...I have to say I wanted this to...because, normally, when you delete a file & re-create it, the creation date is changed, but when you truncate it & then write to it (if AHK had a command to do that) it would leave the date alone. But I've noticed, at least on XP, when you delete & re-create a file soon enough (even outside of AHK), it pulls the old creation date out of it's *ss or something. When I was thinking about this before, I figured I could use...I still want to add better file commands to a future version, such as the ability to 1) overwrite files without having to use FileDelete
file=%A_ScriptName%.txt FileMove, nul, %file%, 1 FileAppend, %A_Now%, %file%...to truncate the file (copy the nul device over it) & then "append" to the newly truncated file...but I just tested it before posting & it didn't work, I tried FileMove, FileCopy, FileMoveDir & FileCopyDir & none of em would copy the nul device over it (errorlevel was silent during the failure too), it just kept appending the new date to the end. This however did work...but is clunky...
file=%A_ScriptName%.txt ;FileMove, nul, %file%, 1 RunWait, cmd /c copy nul "%file%", , hide FileAppend, %A_Now%, %file%...(no, I didn't use %comspec%...lol). Can you make AHK's commands see the nul device (& any other devices it might be supposed to see). This would be good...
FileAppend, Text, Filename [, Trunc]...then we could add a ", 1" to the end of a FileAppend to say "truncate it 1st"...but then "FileAppend" loses it's meaning & should be named "FileWrite"...because a param determines weather it appends or not.
...I would've never tried an empty or non-existent var, I just now tried what I thought would work (above) & it didn't, then I tried...2) The followed was added per the suggestion above:
To create an empty file, write an empty or non-existent variable to it as in this example:
FileAppend, %EmptyVar%, C:\New File.txt
FileAppend, , %file%...& it complained that it wanted param 1 to be non-blank...can you make a blank 1st param be the same as a non-existent var...instead of an error?
Speaking of A_Now, in version 1.0.18 (when there wasn't a FormatTime command, which I still haven't played with yet), I created a subroutine UpdateTime, that would take all the A_?? date vars & convert them to D_?? vars...well, a script is worth a thousand words, so...
UpdateTime: D_MM=%A_MM% D_MM-=0 D_DD=%A_DD% StringTrimLeft, D_YY, A_YYYY, 2 D_H=%A_Hour% D_H-=0 if D_H>12 D_H-=12 D_M=%A_Min% D_S=%A_Sec% if A_Hour<12 D_TT=am else D_TT=pm D_Now=%D_MM%/%D_DD%/%D_YY% %D_H%:%D_M%:%D_S%%D_TT% return...now, this worked for me, but I had to Gosub, UpdateTime every time right before I used D_Now, so I wanted to know if you can add "hot vars" that when accessed, will launch a subroutine to determine it's value...like A_Now always gets the current date...I'd like to create vars that would let me know when they're accessed. Say perhaps define one like...
HotVar, Var [, Subroutine] HotVar, D_Now, UpdateTime...(default subroutine to var name)...you could either enhance "return" to support a return value or just allow the subroutine to assign the "hot var" a value & that would be used (without making the hot var not hot by overwriting it). Can I suggest...A_Date, A_Time & A_LongDate to use the current users format? I (assume I) could use (but haven't tried yet)...
FormatTime, A_Date, , ShortDate FormatTime, A_Time, , Time FormatTime, A_LongDate, , LongDate...to create those vars, but they aren't "hot" like A_Now, so I'd have to Gosub every time before I use em. The YYYYMMDDHH24MISS format might be programmatically useful, but it ain't pretty for display. Is there any easy way to support a number of milliseconds (since 1970 {unix?} or 1980 {dos/windows?}) in the places the YYY... format is accepted? If that format is always 16 bytes, then anything less (or more, omg!) could be assumed to be milliseconds? If it's possible to support both in the same param, could you add a define so I can choose which I want A_Now to return...like...
#A_Now ms ;-or- #TimeFormat ms...coming from JavaScript (& some unix) I expect the "programmatic" time to be milliseconds & not the YYY... thing. Hrm, I just noticed...even with FormatTime, there's no way to get the current ms (of the current second, not since 1970, but you can't get that either)?