Posted 14 July 2012 - 04:33 PM
I want to save a path for each computer ID that communicates with this server, and I save it in the format "[COMPUTER_ID].path".
Stub file contains the default starting directory, which is in this case "/" (on a single line).
I did this so I can change the starting directory easily later on.
Reading works fine, but once I wrote to the file once, readFolder(i) gives errors on me.
If I try to edit the file myself, I get the error: "edit:284: bad argument: string expected, got nil"
Explanation:
writeFolder([COMPUTER_ID],[PATH TO STORE])
in this case I enter "/lol" as the second argument.
Stub file contains the default starting directory, which is in this case "/" (on a single line).
I did this so I can change the starting directory easily later on.
Reading works fine, but once I wrote to the file once, readFolder(i) gives errors on me.
If I try to edit the file myself, I get the error: "edit:284: bad argument: string expected, got nil"
Explanation:
writeFolder([COMPUTER_ID],[PATH TO STORE])
in this case I enter "/lol" as the second argument.
function writeFolder(i,path)
local path = "disk/paths/" .. i .. ".path"
local file = fs.open(path,"w")
file.write(path)
end
function readFolder(i)
local path = "disk/paths/" .. i .. ".path"
print(path)
if (fs.exists(path)) then
local file = fs.open(path,"r")
local returnvalue = file.readLine()
print(returnvalue)
file.close()
return returnvalue
else
fs.copy("disk/stub.path","disk/paths/" .. i .. ".path")
return "/"
end
end