I typed 'help fs' as I did not know what it was, but at the end it has fs.open() modes are [modes]
I don't know what these modes are, could someone tell me what they are?
EDIT: I found what they meant.. Lua 5.1 reference manual. Lol. but the ones with the 'b' on the end still don't make sense.
fs.open() modes?
Started by digpoe, Oct 19 2012 01:41 PM
5 replies to this topic
#1
Posted 19 October 2012 - 01:41 PM
#2
Posted 19 October 2012 - 01:51 PM
The mode denotes how you want to open the file, i.e. if you want to read it, write to it, append to the end of it, etc.
Basically you should be able to use the same modes as described here:
http://www.lua.org/m...tml#pdf-io.open
So e.g. if you'd wanted to open a file for reading in ComputerCraft, you'd use something like...
Basically you should be able to use the same modes as described here:
http://www.lua.org/m...tml#pdf-io.open
So e.g. if you'd wanted to open a file for reading in ComputerCraft, you'd use something like...
local hFile = fs.open( "filename", "r" )... where r stands for read.
#3
Posted 19 October 2012 - 01:54 PM
Thanks.
/>
I was wondering how I would read files too
/>
so, if I wanted to read the words "Hello, world" from a file named "filedata" in a disk in the bottom drive.. wait. I don't know how.. I'm going to guess this?:
local diskdata = ""
sleep(5)
diskdata = fs.open(disk.getMountPath("bottom")["filedata"], "r")
if I'm wrong, please tell me how I would do it.
I was wondering how I would read files too
so, if I wanted to read the words "Hello, world" from a file named "filedata" in a disk in the bottom drive.. wait. I don't know how.. I'm going to guess this?:
local diskdata = ""
sleep(5)
diskdata = fs.open(disk.getMountPath("bottom")["filedata"], "r")
if I'm wrong, please tell me how I would do it.
#4
Posted 19 October 2012 - 02:01 PM
No problem.
Just noticed your edit. The "b" stands for binary mode and allows one to write data to the file in the form of bytes instead of characters/text.
More on writing in binary mode: http://www.lua.org/pil/21.2.2.html
Just noticed your edit. The "b" stands for binary mode and allows one to write data to the file in the form of bytes instead of characters/text.
More on writing in binary mode: http://www.lua.org/pil/21.2.2.html
#5
Posted 19 October 2012 - 02:17 PM
'_' I can't read data from a disk using fs.read()
Is there any way I can read data from a disk?
Is there any way I can read data from a disk?
#6
Posted 19 October 2012 - 02:20 PM
To read data from file "filedata" on a disk below the computer do:
This will fail if the file doesn't exist.
local filename = fs.combine(disk.getMountPath("bottom"), "filedata")
local file = fs.open(filename, "r")
local filedata = file.readAll()
file.close()
This will fail if the file doesn't exist.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











