How do i interact with files in a program?
Started by oxygencraft, Nov 17 2015 05:04 AM
8 replies to this topic
#1
Posted 17 November 2015 - 05:04 AM
What i am trying to do is make an API and i want to make a username and password function so the user needs to enter a username and password to exit to the terminal or something else. Each user will be stored in a file and its the same with the password BUT the passwords is hashed, the passwords are stored in a different file.
#5
Posted 17 November 2015 - 12:28 PM
to read/write text from/to a file you have to get a file handle:
Then depending on what you want to do you use different functions:
Take not that when you open a file using "w", you cannot read from it.
local handle = fs.open(path,"w") -- "w" is for write local handle = fs.open(path,"r") -- "r" is for read local handle = fs.open(path,"a") -- "a" is for append
Then depending on what you want to do you use different functions:
Read: handle.readAll() Write: handle.write(data) Append: handle.write(data)
Take not that when you open a file using "w", you cannot read from it.
Edited by Creator, 17 November 2015 - 12:28 PM.
#8
Posted 19 November 2015 - 02:09 AM
Dog, on 18 November 2015 - 11:21 PM, said:
h.close is not a part of the FS api, it is a part of what is returned from fs.open (which is a table, basically), and it's also listed in the fs.open link above, however it is important and worth noting that you need to close the files as well.
Also, if you accidentally forget to close it (which I have done before) then it's fairly simple to fix it. Simply restart the computer. I'm not positive on whether or not the changes you made to it are kept when you don't close it. If you forget to close it you will often quickly realize because you cannot delete the file or even rename it or open it again as far as I know.
Edited by Twijn, 19 November 2015 - 02:15 AM.
#9
Posted 19 November 2015 - 02:36 AM
Twijn, on 19 November 2015 - 02:09 AM, said:
Dog, on 18 November 2015 - 11:21 PM, said:
h.close is not a part of the FS api, it is a part of what is returned from fs.open (which is a table, basically), and it's also listed in the fs.open link above, however it is important and worth noting that you need to close the files as well.
Also, if you accidentally forget to close it (which I have done before) then it's fairly simple to fix it. Simply restart the computer. I'm not positive on whether or not the changes you made to it are kept when you don't close it. If you forget to close it you will often quickly realize because you cannot delete the file or even rename it or open it again as far as I know.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











