File I/O Functions
Functions for File Input/Output, allowing you to save and load external data.
getTextFromFile
getTextFromFile(path:String, ?ignoreModFolders:Bool = false):String
Loads a File as text and returns its content.
If the file couldn't be found, it will return null.
- file - File name path.
- ignoreModFolders (Optional) - Ignore all files that are not compiled (softcoded files).
Examples:
- getTextFromFile('data/textFile.txt') - Will try to load "mods/My-Mod/data/textFile.txt".
saveFile
saveFile(file:String, content:String, ?absolute:Bool = false):Bool
Returns true if the file was saved successfully.
- file - File name path
- content - Data to save.
- absolute (Optional) - Toggles absolute path.
Examples:
- saveFile('data/textFile.txt', 'Hello World!') - Saves "Hello World!" into a text file in "mods/My-Mod/data/textFile.txt".
- saveFile('mods/My-Mod/data/textFile.txt', 'Hello World!', true) - Same as above but with absolute path.
deleteFile
deleteFile(file:String, ?ignoreModFolders:Bool = false, ?absolute:Bool = false):Bool
Returns true if the file existed and was deleted successfully.
- file - File name path
- ignoreModFolders (Optional) - Ignore all files that are not compiled (softcoded files), does nothing when "absolute" is true.
- absolute (Optional) - Toggles absolute path.
Examples:
- deleteFile('data/textFile.txt') - Deletes file "mods/My-Mod/data/textFile.txt".
- deleteFile('mods/My-Mod/data/textFile.txt', _, true) - Same as above but with absolute path.
directoryFileList
directoryFileList(folder:String):Array<String>
Returns a table with the name of all files inside a mentioned path.
- folder - Absolute folder path.
checkFileExists
checkFileExists(file:String, ?absolute:Bool = false):Bool
Returns true if the file input exists.
- file - File name path
- absolute (Optional) - Toggles absolute path.
Examples:
- checkFileExists('data/myFile.json') - Checks for "mods/My-Mod/data/myFile.json".
- checkFileExists('mods/My-Mod/data/myFile.json', true) - Same as above but with absolute path.