Filesystem

openfolderdialog

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

Syntax

openfolderdialog(options?: DialogOptions): FileSystemItem | nil

Arguments

NameTypeDescription
options?DialogOptionsOptional settings table that controls how the operation behaves.

Returns

NameTypeDescription
folderFileSystemItem | nilSelected folder metadata, or nil when cancelled.

Description

Opens a native folder picker and returns the selected folder 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 folder (FileSystemItem | nil). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Let the user select a folder from a native dialog.

local folder = openfolderdialog({
    title = "Choose a workspace folder",
    defaultPath = "workspace",
})

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