Jump to content




How to you fs.writeLine(text) without deleting the existing text in the file?


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

#1 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 29 October 2012 - 10:43 PM

View PostHithere__, on 29 October 2012 - 08:53 PM, said:

Title says it all.


#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 29 October 2012 - 10:51 PM

Open the file in append mode:
local file = fs.open("path/to/file", "a")
if file then
  file.writeLine("some random text")
  file.close()
end
That way it will write to the end of the file, without deleting the previous contents.

#3 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 29 October 2012 - 11:02 PM

Will it add a line?
Ex.
It writes "1"
then later writes "2"
will the file it writes look like
1
2
or will it look like
12
?

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 29 October 2012 - 11:40 PM

If you use writeLine it will be in a new line, if you use write it will be in the same line.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users