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

fs API: Adding string without deleting previous string in file

Started by moneymaster2012, 15 March 2017 - 11:15 PM
moneymaster2012 #1
Posted 16 March 2017 - 12:15 AM
I need to make a program where the user's input always adds a new line of code (string) to a file. But what I keep getting is each type the user writes a string into a file, the previous code/string is deleted. How do I continually keep adding strings to this one file without the previous code going to trash?
FuzzyLitchi #2
Posted 16 March 2017 - 12:22 AM
you want to use
file = fs.open("file_path_here", "a")

"a" being the important part, this appends to the end of the file.

you can then use
file.writeLine("This line is now appended!")
to append to the end of the file.
Edited on 15 March 2017 - 11:22 PM
moneymaster2012 #3
Posted 16 March 2017 - 12:47 AM
you want to use
file = fs.open("file_path_here", "a")

"a" being the important part, this appends to the end of the file.

you can then use
file.writeLine("This line is now appended!")
to append to the end of the file.
Haha I didn't think of that, thanks. I guess I had trouble because I didn't know what append meant lmao
FuzzyLitchi #4
Posted 16 March 2017 - 02:37 PM
You're welcome :)/>