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

[fs] Question

Started by louiskw, 07 May 2012 - 07:52 AM
louiskw #1
Posted 07 May 2012 - 09:52 AM
Hi, the fs api includes everything i could ever need except the art of creating files. Is there another way to do this or store data indefinately?
Advert #2
Posted 07 May 2012 - 12:40 PM
There is one other way: you could set up a website and use that to store data indefinitely, but I wouldn't recommend it.
Cloudy #3
Posted 07 May 2012 - 01:23 PM
If you open a file in write mode it will create it if it doesn't exist.
Grim Reaper #4
Posted 08 May 2012 - 03:55 AM
Yes. However, like "edit" if there is no information put into the file, it has no reason to save it on your computer or the server.

Example:
If you wanted to create a file to write the version of your program into you might try something like this

version = "1.0" -- The version here does not matter because it is
a string, in case you did not know already :)/>/>
file = fs.open("myProgram/version", "w") -- This here will open the
                              file version in the myProgram directory
                              in write mode and keep it
                              in the file 'stream' if you will, until closed by file.close()

-- Also, a misconception that does not need addressing is the
variable name 'file'. You do not need this name exactly, for all
you need is the variable name you are holding the file instance in.
varname.fileMethod(args)

file.write(version); file.close() -- Writing information of any kind
						 into a file and then closing it will guarantee
						 the successful save of your file.
						 Remember to always always ALWAYS close your file!