selectFile([settings])
Opens a selection dialog that allows to select one file. The settings object can be used to add a prompt text at the top of the dialog, to restrict the selection to certain file types and to set the dialog’s starting folder.
Type: function
Parameter(s):
- settings {Object} Optional:
A settings object to control the function’s behavior.
- settings.prompt {String} Optional:
The prompt text at the top of the file selection dialog. Default:
""
(no prompt) - settings.filter {} Optional:
String or an array containing strings of file endings to include in the dialog. Default:
""
(include all) - settings.folder {} Optional:
Folder or a folder path string defining the start location of the dialog. Default: most recent dialog folder or main user folder.
Returns:
-
{File | Null}:
The selected file. If the user cancels,
null
will be returned.
Example(s):
Open file selection dialog with a prompt text
selectFile({prompt: "Please select a file."});
Open selection dialog starting at the user's desktop, allowing to only select PNG or JPEG files
selectFile({folder: "~/Desktop/", filter: ["jpeg", "jpg", "png"]});