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

New lines in writing to files

Started by mrpoopy345, 16 December 2013 - 04:36 PM
mrpoopy345 #1
Posted 16 December 2013 - 05:36 PM
Hello! I need help. What I want to do is open a file and write a variable to it in a new line of the program.
For ex:
File before I write to it:

Hello
File after I write to it:

Hello
World
Any help?
TheOddByte #2
Posted 16 December 2013 - 06:00 PM
Do you mean the append mode?

--# Creating the file and clearing it if it exists
local file = fs.open("<file>", "w")
file.write("Hello")
file.close()

--# Opening and adding the new data without clearing the file
local file = fs.open("<file>","a")
file.writeLine("World") -- writes to a newline
file.close()

Check out the wiki about fs.open for more information
Edited on 16 December 2013 - 05:02 PM