function fs.write.file(path: string, content: string): number
Creates a new file at specified path
File will contain given content
Returns a return code:
Return Code
Numerical Value
Meaning
SUCCESS
0
The operation has completed successfully
INVALID_PATH
1
The specified path is invalid
INVALID_PARENT_TYPE
2
The parent is a file and not a directory
OVERWRITE_DIR
3
fs.write.file() can not overwrite a directory
NO_PERMS
4
No permission to write file at the specified path
STORAGE_OVERFLOW
5
The operation would cause the storage to fill up
Example usage:
local fs = import("fs.lib")
local success = fs.write.file("root/user/hello.lua", "Hello World!")
if success = 0 then
-- the operation completed successfully
end
The folder that should’ve been removed was not found
NO_PERMS
2
No permission to remove directory
FAILED
3
The operation has failed on the directory children - Data loss is possible
INVALID_FS_STATE
0xDEADBEEF
An invalid file system state. The system will panic when this is returned
Example usage:
local fs = import("fs.lib")
local success = fs.remove.dir("root/user")
if success = 0 then
-- the operation completed successfully
-- this operation will not cause there are no permissions to remove root/user
end
local fs = import("fs.lib")
local success = fs.remove.file("root/bin/console.exe")
if success = 0 then
-- the operation completed successfully
-- this operation will not cause there are no permissions to remove root/bin/console.exe
end
function fs.remove.dir_children(path: string): number
Removes children of a directory excluding the directory
Returns a return code:
| Return Code | Numerical Value | Meaning |
| :———: | :———––: | :—–: |
| SUCCESS | 0 | The operation completed successfully |
| INVALID_DIR | 1 | The folder whose children should’ve been removed was not found |
| NO_PERMS | 2 | No permission to remove children of directory |
| FAILED | 3 | The operation has failed on the directory children - Data loss is possible |
| INVALID_FS_STATE | 0xDEADBEEF | An invalid file system state. The system will panic when this is returned |
Example usage:
local fs = import("fs.lib")
local success = fs.remove.dir_children("root")
if success = 0 then
-- the operation completed successfully
-- this operation will not cause there are no permissions to remove root
end
function fs.get_dir_children(path: string): (number, {string})
Gets all children of a directory
Returns a return code (ret1) and the children (ret2)
| Return Code | Numerical Value | Meaning |
| :———: | :———––: | :—–: |
| SUCCESS | 0 | The operation completed successfully |
| INVALID_PATH | 1 | The directory to get children of is invalid |
| INVALID_PROP | 2 | This should never be returned as it is logically impossible to achieve |
function fs.get_final_path(path, optional_start): string
Starts in the working directory or optional_start, then normalizes the given path and returns it
Example usage:
local fs = import("fs.lib")
local normalized = fs.get_final_path("../lib/../bin", "root/bin")
--[[
normalized is now "root/bin", because:
1. we start in root/bin
2. we go back (..) into root
3. we go in root/lib
4. we go back (..) into root
5. we go in root/bin
]]
function fs.get_final_path_ignore_existence(path, optional_start): string
Starts in the working directory or optional_start, then normalizes the given path and returns it
Can go one file deeper (inexistent)
Example usage:
local fs = import("fs.lib")
local normalized = fs.get_final_path("../lib/../bin/inexistent_file.exe", "root/bin")
--[[
normalized is now "root/bin/inexistent_file.exe", because:
1. we start in root/bin
2. we go back (..) into root
3. we go in root/lib
4. we go back (..) into root
5. we go in root/bin
6. we go in root/bin/inexistent_file.exe
this is useful for programs such as mkdir or touch