Filesystem

savefiledialog

Opens a native save dialog and writes the provided content when the user chooses a path.

Syntax

savefiledialog(content: string, options?: DialogOptions): FileSystemItem | nil

Arguments

NameTypeDescription
contentstringText or byte string to write.
options?DialogOptionsOptional settings table that controls how the operation behaves.

Returns

NameTypeDescription
fileFileSystemItem | nilSelected file metadata, or nil when the dialog is cancelled.

Description

Opens a native save dialog and writes the provided content when the user chooses a path.

Call it with 2 parameter(s): content, options. The argument table explains which values are required and which ones only refine the behavior.

It returns file (FileSystemItem | nil). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Let the user choose where to save generated content.

local saved = savefiledialog("Example output", {
    title = "Save output",
    suggestedName = "output.txt",
    defaultExtension = "txt",
})

if saved then
    print(saved)
end

Types

DialogOptions

Configures the native file or folder selection dialog.

title? string Sets the dialog window title.defaultPath? string Selects the directory shown when the dialog opens.extensionFilter? {string} Limits selectable files to the listed extensions, with or without a leading dot.suggestedName? string Provides the initial file name in save dialogs.defaultExtension? string Sets the extension used when the entered file name has none.