Originally Posted by
psycore
With Toribash you can only access files in the Toribash folder.
For the rest:
-- you can open many files at the same time:
local input = io.open("path/to/the/file.xml", "r") --read acces
local output = io.open("out.txt", "w") -- write acces
-- multiple ways to read:
-- line for line
for line in input:lines() do
echo(line) -- print line to screen
end
-- cursor is now at end of file, let's put it back to the beginning
input:seek("set")
-- read whole file:
local text = input:read("*a")
input:seek("set")
-- read line:
local aLine = input:read("*l")
-- five chars:
local fiveChars = input:read(5)
--enough about reading
input:close()
-- now to writing. let's write the text of input to output:
output:write(text)
-- for demonstration let's put "LUA" at the middle of the file:
local fileSize = output:seek("end")
output:seek("set", math.floor(fileSize/2))
-- keep in mind that this overwrites the previous file content!
output:write("LUA")
output:flush
output:close
I did these fraction by fraction: I am getting results for most of them....
this was fine
> local output = io.open("out.txt", "w")
> local text = "hi this is the text file!!"
but how to chk the file is created or not?? what is the default location where the file get created?? can we change that??
-----
I tried to do the filesizing operation: it gave me this error:
> local fileSize = output:seek("end")
stdin:1: attempt to index global 'output' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?
then I decided to write directly:
> output:write("LUA")
this also gave me the error:
stdin:1: attempt to index global 'output' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?
please help Sir...
-----
I have one doubt, if I open one file in the read and write mode I want to search one word which is there in that file several times... How can I do that... I want to add one more line next to that word.....
Please help, Thanks in advance!!
Last edited by pranavkulkarni; Jul 5, 2012 at 04:49 PM.
Reason: <24 hour edit/bump