Page 1 of 1

Append info to file

Posted: Sat Feb 02, 2019 1:05 pm
by GMKai

Code: Select all

Function p_WriteLog(logline)
    Local str$ = ""
    ;OpenFile(1, "t:test.log",#MODE_WRITE)
    OpenFile(1, "t:test.log",#MODE_READWRITE)
    Seek(1,#EOF)
    str$ = logline.."\n"
    WriteString(1, str$)
    CloseFile(1)
EndFunction

DeleteFile("t:test.log")
p_WriteLog("ABC")
p_WriteLog("Test2") 
With the snippet above the logfile gets created and information can be appended.
Why does this not work with mode "#MODE_WRITE"?

Re: Append info to file

Posted: Sat Feb 02, 2019 4:00 pm
by airsoftsoftwair
#MODE_WRITE will always create a blank file. If you want to modify an existing file, you have to use #MODE_READWRITE, even if you don't want to read but just append.

Re: Append info to file

Posted: Sun May 12, 2019 10:25 pm
by amyren
airsoftsoftwair wrote: Sat Feb 02, 2019 4:00 pm #MODE_WRITE will always create a blank file. If you want to modify an existing file, you have to use #MODE_READWRITE, even if you don't want to read but just append.
Perhaps that could be explained in the OpenFile docs as well, if you care to add it at next update?
Or is it described elsewhere?