Skip to content
File systemReferenceNew · 0.744

writefileasync

Create or replace a local file asynchronously.

Details#

Writes the supplied bytes to a workspace file, creating it if needed. An existing file is truncated before writing; this is a replacement operation, not an append. Parent directories are not created automatically. A failed write can leave a changed or incomplete file, so success must be checked before using it.

Signature#

Luau
writefileasync(path: string, data: string): (boolean?, string?)

Parameters#

ParameterTypeDescription
pathstringA file path inside your workspace. The parent directory must already exist for writes.
datastringThe bytes to write; binary strings are supported.

Returns#

On success, true. On an I/O failure, nil and an error string. Invalid arguments or paths raise an error.

Examples#

Local example

Luau
local ok, err = writefileasync("notes.txt", "Local note\n")
if not ok then
    warn(err)
end

Notes#

  • The call yields until the operation finishes, then returns its result. It does not return a promise or take a callback.
  • Invalid argument types and rejected paths raise an error. A file I/O failure instead returns nil and an error string; check both results.