Filesystem

openfolderdialog

Opens a Windows folder picker with Windows file picker with folder selection mode and returns the selected folder as a file item.

Syntax

openfolderdialog(options?: DialogOptions): FileSystemItem | nil

Arguments

NameTypeDescription
options?DialogOptionsOptional table. For openfolderdialog, title and defaultPath are used. defaultPath is applied only when it resolves to an existing directory. extensionFilter is accepted by the shared dialog options parser but folder selection is enabled with folder selection mode.

Returns

NameTypeDescription
folderFileSystemItem | nilSelected folder item, or nil when the dialog is cancelled. Dialog failures throw Failed to open folder dialog.

Description

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

Example

Let the user select a folder and handle the selected folder item or cancellation.

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

if folder then
    print(folder:GetName())
    print(folder:IsFolder())
else
    print("No folder selected")
end

Types

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.