Syntax
openfiledialog(options?: DialogOptions): FileSystemItem | nilArguments
| Name | Type | Description |
|---|---|---|
options? | DialogOptions | Optional table. For openfiledialog, title, defaultPath, and extensionFilter are used. extensionFilter is a table of extension strings; leading . or *. is stripped before each filter becomes *.<extension>. |
Returns
| Name | Type | Description |
|---|---|---|
file | FileSystemItem | nil | Selected file item, or nil when the dialog is cancelled or no selected filesystem path is returned. Dialog failures throw Failed to open file dialog. |
Description
Opens a Windows file-open dialog with Windows file picker and returns the selected file as a file item.
Call it with 1 parameter(s): 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
Open a file picker and handle the selected file item or cancellation.
local file = openfiledialog({
title = "Choose a configuration",
defaultPath = ".",
extensionFilter = { "json", "txt" },
})
if file then
print(file:GetName())
print(file:IsFile())
else
print("No file selected")
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.