Repository navigation
Library: File System
Aviril edited this page Nov 29, 2024
·
7 revisions
File module simulates file system as may have been observed in other languages (Javascript for example). Custom file manager module was essentially needed for us due to our usecase reasons also since MTA not being capable of supporting relative file paths (Cringe?🤣)
Add the below code once in either of the shared .lua script of the resource you want to use within:
--Declare it globally only once
loadstring(exports.assetify_library:import("filesystem"))()local bool: result = assetify.file:exists(
string: path
)local bool: result = assetify.file:delete(
string: path
)local string: result = assetify.file:read(
string: path
)local bool: result = assetify.file:write(
string: path,
string: data
)local table: result = assetify.file:parseURL(
string: path
)
result: {
pointer = string: pointer, --rootDir (~/url) / localDir (@/url) / false
url = string: url
extension = string: extension, --Extension of file. (If detected any)
file = string: file --Name of file. (If detected any)
directory = string: directory --Directory list the file is located within. (If detected any)
}local string: result = assetify.file:resolveURL(
string: path, --This can be relative path such as "@/dirA/dirB/dirC/.../.../dirD/file.json", "~/dirA/dirB/dirC/.../.../dirD/file.json", "dirB/dirC/.../.../dirD/file.json" etc
string: chroot --(Optional) If specified resolver will be limited within specified chroot's scope
)