Volt

appendfile

Appends data to the end of a file.

Syntax

appendfile(path: string, data: string) -> void

Parameters

ParameterTypeDescription
pathstringThe file path
datastringThe data to append

Returns

This function does not return a value.

Description

appendfile adds data to the end of an existing file without overwriting its contents. If the file doesn't exist, it will be created.

Example

-- Create initial file
writefile("log.txt", "Log started\n")

-- Append entries
appendfile("log.txt", "Entry 1: Hello\n")
appendfile("log.txt", "Entry 2: World\n")

-- Read the result
print(readfile("log.txt"))
--[[
Log started
Entry 1: Hello
Entry 2: World
]]

Logging Example

local function log(message)
    local timestamp = os.date("%Y-%m-%d %H:%M:%S")
    appendfile("debug.log", "[" .. timestamp .. "] " .. message .. "\n")
end

log("Script started")
log("Player joined")
log("Event triggered")

On this page