File - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
Utility for interacting with the file system.
local file = require 'ghostutil.file'write(filePath: string, content: string): voidWrites onto the specified file with the given filePath.
Parameters:
-
filePath: The path to the target file. (absolute) -
content: The new file content to write onto the file. (overwrite)
View Example
-- sets the content of the file "info.txt" to: "You are currently running GhostUtil!!"
-- if "info.txt" had any contents before executing file.write, it will be overwritten by the contents passed into file.write.
file.write('info.txt', 'You are currently running GhostUtil!!')─────────────────────────
append(filePath: string, content: string): voidAppends onto the specified file with the given filePath. This would mean it'd write content at the end of the file instead of overriding it's contents.
Parameters:
-
filePath: The path to the target file. (absolute) -
content: The content to append onto the file.
View Example
--[[
let's assume that "info.txt" had this as the file content: [
what a nice day.
i just woke up..
]
]]
-- let's add a new line that says "hello world!".
file.append('info.txt', '\nhello world!')
--[[
info.txt should look like this now: [
what a nice day.
i just woke up..
hello world!
]
]]─────────────────────────
read(filePath: string): stringReads the specified file with the given filePath.
Parameters:
-
filePath: The path to the target file to read. (absolute)
Returns: The file contents.
View Example
--[[
assuming that "info.txt" had the content: [
salmon is tasting great today,
i love them code.
]
]]
-- let's try reading info.txt's contents..
file.read('info.txt')
--[[
this should return the exact file content: [
salmon is tasting great today,
i love them code.
]
]] ─────────────────────────
exists(filePath: string): booleanChecks if the specified file with the given filePath exists.
Warning
Result might not be accurate in Psych Engine 0.6.3 if ran before onCreate or outside a callback.
Using it in an appropriate callback instead is highly recommended.
Parameters:
-
filePath: The path to the target file to check. (absolute)
Returns: If the file exists.
View Example
--[[
assuming the file system looks like this:
- assets/
- mods/
- PsychEngine.exe
- info.txt
]]
file.exists('info.txt')
-- it exists, so this should return true.
file.exists('EVILinfo.txt')
-- this doesnt exist in the file system, so it returns false..─────────────────────────
isDirectory(filePath: string): booleanChecks whether the provided filePath leads to a directory or a normal file.
Caution
This function is unavailable outside a callback in Psych Engine 0.6.3,
Please run it in an appropriate callback instead.
Parameters:
-
filePath: The path to the target file to check. (absolute)
Returns: If the file is a directory.
View Example
-- naturally, "assets" is a folder, so this should return true.
file.isDirectory('assets')─────────────────────────
readDirectory(filePath: string): table<string>Returns a table of file names that exists in the specified directory.
(This function already assumes that the filePath inputted is a directory. External checks may be needed.)
Caution
This function is unavailable outside a callback in Psych Engine 0.6.3,
Please run it in an appropriate callback instead.
Parameters:
-
filePath: The path of the directory to read from. (absolute)
Returns: A table of file names in the directory.
View Example
--[[
assuming this is the file system:
- assets/
| ...
- mods/
| - thing.txt
| - todoList.txt
| - keoiki.png
- emptyFolder/
- PsychEngine.exe
]]
file.readDirectory('mods')
-- this will return the following table:
{
'thing.txt',
'todoList.txt',
'keoiki.png'
}
-- however, calling readDirectory on an empty folder returns an empty table ({ }).
file.readDirectory('emptyFolder')─────────────────────────
move(filePath: string, newPath: string): voidMoves the specified file in filePath to a new location given by newPath.
Parameters:
-
filePath: The path of the target file to move. (absolute) -
newPath: The new location to move it to. (absolute)
View Example
--[[
assuming this is the file system:
- assets
| ...
- someFolder/
| - supersecretplan.txt
- mods/
| - info.txt
| - keoiki.png
- PsychEngine.exe
]]
-- doing this will move "info.txt" file from the mods folder to the "someFolder" folder.
file.move('mods/info.txt', 'someFolder')
--[[
so afterwards, it should look like this:
- assets
| ...
- someFolder/
| - info.txt
| - supersecretplan.txt
- mods/
| - keoiki.png
- PsychEngine.exe
]]
GhostUtil 3.0.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.