Posted 31 August 2016 - 06:13 PM
So you might be asking yourself?
How do i use the file system in my program?
I know how i used to not be able to know the filesystem commands. But now i know and i want to share the same experience i know to you.
Filesystem Commands:
Syntax:
fs.open(<path>, <r/w>
Examples:
Writing:
myfile = fs.open("/test", "w") – Opens the file in write mode, will create the file if it does not exist
myfile.write("Testing") – Writes Testing to the file
myfile.close() – Closes the file so the system is no longer using the file
Reading:
myfile = fs.open("/test", "r") – Opens the file in read-only mode
line = myfile.readLine() – Stores the line in a variable
OR
code = myfile.readAll() – Reads all the code and stores it in a variable
myfile.close() – Closes the file so the system is no longer using the file
Syntax:
fs.exists(<file>)
Example:
if fs.exists("/myFile") == true then
– Run's this code if file exists
print("myFile exists!")
else
print("myFile does not exist!")
end
Syntax:
fs.delete(<name>)
Example:
fs.delete("/myFile")
Syntax:
fs.move(source, destination)
Example:
fs.move("/myFile", "/Folder/myFile")
Syntax:
fs.copy(source, destination)
Example:
fs.copy("/myFile", "/Folder/myFile")
There will be more filesystem tutorials later, but this is what I know right now. Thank You!
How do i use the file system in my program?
I know how i used to not be able to know the filesystem commands. But now i know and i want to share the same experience i know to you.
Filesystem Commands:
fs.open()
fs.open will open a file so you can write/read to it, You will need to save it to a variable.Syntax:
fs.open(<path>, <r/w>
Examples:
Writing:
myfile = fs.open("/test", "w") – Opens the file in write mode, will create the file if it does not exist
myfile.write("Testing") – Writes Testing to the file
myfile.close() – Closes the file so the system is no longer using the file
Reading:
myfile = fs.open("/test", "r") – Opens the file in read-only mode
line = myfile.readLine() – Stores the line in a variable
OR
code = myfile.readAll() – Reads all the code and stores it in a variable
myfile.close() – Closes the file so the system is no longer using the file
fs.exists()
fs.exists will return true or false depending if the file exists, You need to have an if statementSyntax:
fs.exists(<file>)
Example:
if fs.exists("/myFile") == true then
– Run's this code if file exists
print("myFile exists!")
else
print("myFile does not exist!")
end
fs.delete()
Delete's a fileSyntax:
fs.delete(<name>)
Example:
fs.delete("/myFile")
fs.move()
Move's a file from one location to another locationSyntax:
fs.move(source, destination)
Example:
fs.move("/myFile", "/Folder/myFile")
fs.copy()
Copy's a file from one location to another locationSyntax:
fs.copy(source, destination)
Example:
fs.copy("/myFile", "/Folder/myFile")
There will be more filesystem tutorials later, but this is what I know right now. Thank You!