FileSelectFolder

Displays a standard dialog that allows the user to select a folder.

FileSelectFolder, OutputVar , StartingFolder, Options, Prompt

Parameters

OutputVar

The name of the output variable in which to store the user's selected folder. This will be made blank if the user cancels the dialog (i.e. does not wish to select a folder). If the user selects a root directory (such as C:\), OutputVar will contain a trailing backslash. If this is undesirable, remove it as follows:

FileSelectFolder, Folder
Folder := RegExReplace(Folder, "\\$")  ; Removes the trailing backslash, if present.
StartingFolder

If blank or omitted, the dialog's initial selection will be the user's My Documents folder or possibly This PC (formerly My Computer or Computer). A CLSID folder such as ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} (i.e. This PC) may be specified start navigation at a specific special folder.

Otherwise, the most common usage of this parameter is an asterisk followed immediately by the absolute path of the drive or folder to be initially selected. For example, *C:\ would initially select the C drive. Similarly, *C:\My Folder would initially select that particular folder.

The asterisk indicates that the user is permitted to navigate upward (closer to the root) from the starting folder. Without the asterisk, the user would be forced to select a folder inside StartingFolder (or StartingFolder itself). One benefit of omitting the asterisk is that StartingFolder is initially shown in a tree-expanded state, which may save the user from having to click the first plus sign.

If the asterisk is present, upward navigation may optionally be restricted to a folder other than Desktop. This is done by preceding the asterisk with the absolute path of the uppermost folder followed by exactly one space or tab. For example, C:\My Folder *C:\My Folder\Projects would not allow the user to navigate any higher than C:\My Folder (but the initial selection would be C:\My Folder\Projects).

Options

If blank or omitted, it defaults to 1. Otherwise, specify one of the following numbers:

0: The options below are all disabled (except on Windows 2000, where the "make new folder" button might appear anyway).

1: A button is provided that allows the user to create new folders.

Add 2 to the above number to provide an edit field that allows the user to type the name of a folder. For example, a value of 3 for this parameter provides both an edit field and a "make new folder" button.

[v1.0.48+]: Add 4 to the above number to omit the BIF_NEWDIALOGSTYLE property. Adding 4 ensures that FileSelectFolder will work properly even in a Preinstallation Environment like WinPE or BartPE. However, this prevents the appearance of a "make new folder" button, at least on Windows XP.

If the user types an invalid folder name in the edit field, OutputVar will be set to the folder selected in the navigation tree rather than what the user entered, at least on Windows XP.

This parameter can be an expression.

Prompt

If blank or omitted, it defaults to Select Folder - %A_ScriptName% (i.e. the name of the current script). Otherwise, specify the text displayed in the window to instruct the user what to do.

Error Handling

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to 1 if the user dismissed the dialog without selecting a folder (such as by pressing the Cancel button). It is also set to 1 if the system refused to show the dialog (rare). Otherwise, it is set to 0.

Remarks

A folder-selection dialog usually looks like this:

FileSelectFolder

A GUI window may display a modal folder-selection dialog by means of Gui +OwnDialogs. A modal dialog prevents the user from interacting with the GUI window until the dialog is dismissed.

FileSelectFile, MsgBox, InputBox, ToolTip, GUI, CLSID List, FileCopyDir, FileMoveDir, SplitPath

Also, the operating system offers standard dialog boxes that prompt the user to pick a font, color, or icon. These dialogs can be displayed via DllCall() as demonstrated at GitHub.

Examples

Allows the user to select a folder and provides both an edit field and a "make new folder" button.

FileSelectFolder, OutputVar, , 3
if (OutputVar = "")
    MsgBox, You didn't select a folder.
else
    MsgBox, You selected folder "%OutputVar%".

A CLSID example. Allows the user to select a folder in This PC (formerly My Computer or Computer).

FileSelectFolder, OutputVar, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}