Append to a .txt file

Hendrik R.
Bad Sassendorf,

Sep 23, 2022
26 Posts

0  |  1  

Re: Append to a .txt file

I have a question about the file I/O procedures.
How can I append a string to the end of an existing .txt file?

If I use only the FileWrite procedure, the lines are always replaced by the last call of the FileWrite procedure.

I think that the filepointer must be incremented, but I don't know how.


!File Open/Create
hFile = FileOpen(sFileName)
If hFile = -1 Then
    print "Unable to Open file: ", sFileName, " Attempting to Create"
    hFile = FileCreate(sFileName)
    if hFile = -1 Then
        print "Unable to create file: ", sFileName

!File Read
i=FileRead(hFile, s)

! File Write
FileWrite(hFile, Test.Name + ":" + "0.014",,"\r\n")

!File Close
If FileClose(hFile) <> 0 Then
    Print "Error During FileClose..."

**Code End**


Solution Available
Paul T.
Maennedorf, Zurich

Sep 23, 2022
64 Posts

3  |  0  

Re: Append to a .txt file

Hi Hendrik,

I think you need to use the FileSeek(...) function before the FileWrite(...).
Something like this:

FileSeek(hFile, 0, aFileOriginEnd) ! positions the file pointer to the end of the file.

Best regards,

Hendrik R.
Bad Sassendorf,

Sep 25, 2022
26 Posts

0  |  0  

Re: Append to a .txt file

Hi Paul,

Thank you, it works now!


Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]