Syntax
savefiledialog(content: string, options?: DialogOptions): FileSystemItem | nilArguments
| Name | Type | Description |
|---|---|---|
content | string | Lua string bytes to write to the selected file. The file is opened in binary truncate mode after the user confirms a path. |
options? | DialogOptions | Optional table. savefiledialog uses title, defaultPath, extensionFilter, suggestedName, and defaultExtension. extensionFilter is a table of extension strings; leading . or *. is stripped before each filter becomes *.<extension>. defaultExtension strips leading . characters before it is passed to SetDefaultExtension. |
Returns
| Name | Type | Description |
|---|---|---|
file | FileSystemItem | nil | Saved file item, or nil when the dialog is cancelled. Dialog or write failures throw Failed to save file. |
Description
Opens a Windows save dialog with Windows save dialog, writes the provided Lua string bytes to the selected path, and returns the saved file as a file item.
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
Write generated content to a path chosen by the user and handle the saved file item.
local saved = savefiledialog("Example output", {
title = "Save output",
suggestedName = "output.txt",
defaultExtension = "txt",
extensionFilter = { "txt" },
})
if saved then
print(saved:GetName())
print(saved:IsFile())
else
print("No file saved")
endTypes
DialogOptions
Configures the Windows 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.