Syntax
writefile(path: string, content: string)Aliases
writefileasyncArguments
| Name | Type | Description |
|---|---|---|
path | string | File path resolved inside the workspace after separator normalization, workspace-boundary checks, and filename/extension checks. Absolute paths are accepted only if they resolve inside the workspace. |
content | string | Lua string bytes to write. The data is written in binary truncate mode; writefile does not add newlines, BOM bytes, null terminators, or other extra bytes. |
Description
Writes Lua string bytes to a file inside the workspace, creating missing parent directories and replacing the file contents if the file already exists.
Call it with 2 parameter(s): path, content. The argument table explains which values are required and which ones only refine the behavior.
It does not return data. Treat the call as an action and handle errors around the call site when needed.
Example
Write bytes to a workspace file and replace any existing contents.
local path = "examples/config.json"
writefile(path, '{"enabled":true}')
print(readfile(path))
writefile(path, "")
print(#readfile(path))