FileSelectFolder

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

FileSelectFolder, OutputVar [, StartingFolder, Options, Prompt]

 

Parameters

OutputVar

The name of the 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
StringRight, LastChar, Folder, 1
if LastChar = \
	StringTrimRight, Folder, Folder, 1 ; Remove the trailing backslash.
StartingFolder

If blank or omitted, the dialog's initial selection will be the user's My Documents folder (or possibly My Computer).

Otherwise, the most common usage of this parameter in v1.0.36.03+ 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; and *C:\My Folder would initially select a 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).

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. In the following example, the user would not be allowed to navigate any higher than C:\My Folder (but the initial selection would be C:\My Folder\Projects):
C:\My Folder *C:\My Folder\Projects

Options

One of the following numbers:
0: None of the below options is enabled. Note: On Windows 2000, the "make new folder" button might appear anyway.

1 (default): A button is provided that allows the user to create new folders. However, the button will not be present on operating systems older than Windows Me/2000/XP.

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.

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.

In v1.0.30.03+, this parameter can be an expression.

Prompt Text displayed in the window to instruct the user what to do. If omitted or blank, it will default to "Select Folder - %A_SCRIPTNAME%" (i.e. the name of the current script).

 

Remarks

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.

 

Related

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

 

Example

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