Append info to file

Find quick help here to get you started with Hollywood
Post Reply
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Append info to file

Post 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"?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Append info to file

Post 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.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Append info to file

Post 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?
Post Reply