5 posts
Posted 21 July 2012 - 12:44 PM
Is it possible to go up a level when using fs.open
I tried this
users = fs.open("../users", "r")
but it gave me the error
addid:18: attempt to index ? (a nil value)
Thanks for any help
864 posts
Location
Sometime.
Posted 21 July 2012 - 12:48 PM
You are opening a directory
You need to open the files
userTbl = fs.list("../users")
for i = 1,#userTbl do
hFile = fs.open(userTbl, "r")
readFile = hFile.readAll()
hFile.close()
end
EDIT: IDK if this works (untested) but it should..
88 posts
Location
Austria(German)
Posted 21 July 2012 - 12:49 PM
If I aren't wrong then fs.open is using the absolute path and not the local path of the program!
users = fs.open("users","r")
Edit: Sorry I've missed the question :)/>/>
864 posts
Location
Sometime.
Posted 21 July 2012 - 12:51 PM
users.close() – That should be ur error if you aren't closing it.
Why do you need to open it?
5 posts
Posted 21 July 2012 - 01:16 PM
Here is my whole code at the moment
while true do
shell.run("clear")
print("Computer ID :".. os.computerID())
print("TT Industries")
print("Add to authentication list")
print("-------------------------------------------------")
print("")
print("Computer ID to add: ")
text = read()
while true do
users = fs.open("../users", "r")
while true do
line = users.readLine()
if not line then
users.close()
print("User not found. Authenticating...")
users = fs.open("../users", "a")
users.writeLine(text)
users.close()
print("User added to list")
break
else
if line == text then
users.close()
print("ID already authenticated.")
break
end
end
end
break
end
end
It used to work with just "users" but when I moved the file back a level and tried "../users" that did not work
864 posts
Location
Sometime.
Posted 21 July 2012 - 01:20 PM
users = fs.open("../users", "a") - Why not just "w"
You are still opening a directory, what is your main goal?
5 posts
Posted 21 July 2012 - 01:30 PM
My goal is to append the user ID the user file that's what I thought "a" was for.
http://computercraft...p?title=Fs.openAlso the users file does not have an extension as I created it using the computer on my world
864 posts
Location
Sometime.
Posted 21 July 2012 - 01:43 PM
The ID..
You should fs.open(text, "r")
5 posts
Posted 21 July 2012 - 02:19 PM
I don't think you understand me.
This is the process
1) User inputs id to add to list
2) Computer opens users and adds whatever the user in-putted onto the list
fs.open(text, "a")
Would open a file with a name of the user ID and not the user list file which is "users" (Doesn't have an extension)
864 posts
Location
Sometime.
Posted 21 July 2012 - 03:41 PM
I see, You are writing a new line for that ID.
do fs.open("names", "a") – ../names is a dir
8543 posts
Posted 21 July 2012 - 09:15 PM
What are you trying to do with this whole "move back a level" thing? Are you trying to read/write to files inside the computer's file system, or outside of it? If you're trying to go to the folder that contains to root of the computer's filesystem in your actual filesystem (that is, trying to access the /computer/ directory inside your world folder), you can't. Also, the fs API needs absolute paths, and the .. mechanism is relative pathing.