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

how do you edit a file using fs api?

Started by thegreatstudio, 01 May 2013 - 09:59 AM
thegreatstudio #1
Posted 01 May 2013 - 11:59 AM
because i have a program that uses fs api but i dont know how it use it to edit programs.. like startups, programms and more
remiX #2
Posted 01 May 2013 - 12:04 PM
To open a file, clear it and then write use "w" mode

local file = fs.open("startup", "w")
file.write([[--Use multi string lines
--for it to be

--spread over
--multiple lines

print("hi")]])
file.close()

Use "a" mode to append to the file.
local file = fs.open("startup", "a")
file.write([[--This text
--should be found at the end of the startup file
print("Appended successfully!")]])
file.close()
thegreatstudio #3
Posted 01 May 2013 - 12:23 PM
To open a file, clear it and then write use "w" mode

local file = fs.open("startup", "w")
file.write([[--Use multi string lines
--for it to be

--spread over
--multiple lines

print("hi")]])
file.close()

Use "a" mode to append to the file.
local file = fs.open("startup", "a")
file.write([[--This text
--should be found at the end of the startup file
print("Appended successfully!")]])
file.close()

you are a great help remix! Thanks for your answer :)/>