Filesystem

openfiledialog

Opens a native file picker and returns the selected file metadata.

Syntax

openfiledialog(options?: DialogOptions): FileSystemItem | nil

Arguments

NameTypeDescription
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 file picker and returns the selected file metadata.

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 with a title and extension filter.

local file = openfiledialog({
    title = "Choose a configuration",
    defaultPath = "workspace",
    extensionFilter = { "json", "txt" },
})

if file then
    print(file)
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.