This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
whatsfast's profile picture

[Question]Writing onto a file

Started by whatsfast, 29 November 2012 - 03:56 PM
whatsfast #1
Posted 29 November 2012 - 04:56 PM
Whenever I write onto a file it deletes what is before.


mailbody = fs.open(to, "w")
   mail = fs.open(to, "w")
   mail.writeLine("FromId: " .. id)
   mail.writeLine("FromName: " .. name)
   mail.writeLine("To: " .. to)
   mail.write(message..table.concat(mailbody,',\n'))
   mail.close()
Lyqyd #2
Posted 29 November 2012 - 05:34 PM
Not really sure what you're trying to do there. Please give us the full code.

I think what you may be looking for is append mode, though.
Dlcruz129 #3
Posted 29 November 2012 - 05:54 PM
Instead of using fs.open(file, "w"), use fs.open(file, "a")

This opens the file in append mode. Write mode clears the file first, but append mode appends to the end of the file.