Jump to content




[Question]Writing onto a file


  • You cannot reply to this topic
2 replies to this topic

#1 whatsfast

  • New Members
  • 35 posts

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()


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#3 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users