Displays a standard dialog that allows the user to select file(s).

FileSelectFile, OutputVar [, Options, RootDir\Filename, Prompt, Filter]



OutputVar The name of the variable in which to store the filename(s) selected by the user. This will be made blank if the user cancels the dialog (i.e. does not wish to select a file).

If omitted, it will default to zero, which is the same as having none of the options below.

M [v1.0.25.05+]: Multi-select. Specify the letter M to allow the user to select more than one file via shift-click, control-click, or other means. M may optionally be followed by a number as described below (for example, both M and M1 are valid). To extract the individual files, see the example at the bottom of this page.

S: Save button. Specify the letter S to cause the dialog to always contain a Save button instead of an Open button. S may optionally be followed by a number (or sum of numbers) as described below (for example, both S and S24 are valid).

Even if M and S are absent, the following numbers can be used. To put more than one of them into effect, add them up. For example, to use 8 and 16, specify the number 24.

1: File Must Exist
2: Path Must Exist
8: Prompt to Create New File
16: Prompt to OverWrite File
4 (Obsolete in v1.0.25.06+): Since this multi-select method produces an unfriendly format, it is recommended that the M option (above) be used instead.

If the "Prompt to Overwrite" option is present without the "Prompt to Create" option, the dialog will contain a Save button rather than an Open button. This behavior is due to a quirk in Windows.


If present, this parameter contains one or both of the following:

RootDir: The root (starting) directory, which is assumed to be a subfolder in %A_WorkingDir% if an absolute path is not specified. If omitted or blank, the starting directory will be a default that might depend on the OS version. In WinNT/2k/XP and beyond, it will likely be the directory most recently selected by the user during a prior use of FileSelectFile.

Filename: The default filename to initially show in the dialog's edit field. Only the naked filename (with no path) will be shown. To ensure that the dialog is properly shown, ensure that no illegal characters are present (such as /<|:").


C:\My Pictures\Default Image Name.gif  ; Both RootDir and Filename are present.
C:\My Pictures  ; Only RootDir is present.
My Pictures  ; Only RootDir is present, and it's relative to the the current working directory.
My File  ; Only Filename is present (but if "My File" exists as a folder, it is assumed to be RootDir).
Prompt Text displayed in the window to instruct the user what to do. If omitted or blank, it will default to "Select File - %A_SCRIPTNAME%" (i.e. the name of the current script).

Indicates which types of files are shown by the dialog.

Example: Documents (*.txt)
Example: Audio (*.wav; *.mp2; *.mp3)

If omitted, the filter defaults to All Files (*.*). An option for Text Documents (*.txt) will also be available in the dialog's "files of type" menu.

Otherwise, the filter uses the indicated string but also provides an option for All Files (*.*) in the dialog's "files of type" drop-down list. To include more than one file extension in the filter, separate them with semicolons as illustrated in the example above.



If the user didn't select anything (e.g. pressed CANCEL), OutputVar is made blank.

If multi-select is not in effect, OutputVar is set to the full path and name of the single file chosen by the user.

If the M option (multi-select) is in effect, OutputVar is set to a list of items, each of which except the last is followed by a linefeed (`n) character. The first item in the list is the path that contains all the selected files (this path will end in a backslash only if it is a root folder such as C:\). The other items are the selected filenames (without path). For example:
C:\My Documents\New Folder [this is the path in which all the files below reside]
test1.txt [these are the naked filenames: no path info]
... etc.
(The example at the bottom of this page demonstrates how to extract the files one by one.)

When multi-select is in effect, the sum of the lengths of the selected filenames is limited to 64 KB. Although this is typically enough to hold several thousand files, OutputVar will be made blank if the limit is exceeded.

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

Obsolete option: In v1.0.25.06+, the multi-select option "4" is obsolete. However, for compatibility with older scripts, it still functions as it did before. Specifically, if the user selects only one file, OutputVar will contain its full path and name followed by a linefeed (`n) character. If the user selects more than one file, the format is the same as that of the M option described above, except that the last item also ends in a linefeed (`n).



FileSelectFolder, MsgBox, InputBox, ToolTip, GUI, parsing loop, SplitPath



FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt; *.doc)
if SelectedFile =
	MsgBox, The user didn't select anything.
	MsgBox, The user selected the following:`n%SelectedFile%

FileSelectFile, files, M3  ; M3 = Multiselect existing files.
if files =
	MsgBox, The user pressed cancel.
Loop, parse, files, `n
	if a_index = 1
		MsgBox, The selected files are all contained in %A_LoopField%.
		MsgBox, 4, , The next file is %A_LoopField%.  Continue?
		IfMsgBox, No, break