uigetfile

Displays a dialog for selecting existing file(s). Multiple files can be selected using the Ctrl key.

Syntax

[name, filepath, index] = uigetfile()

[name, filepath, index] = uigetfile(filters)

[name, filepath, index] = uigetfile(filters, caption)

[name, filepath, index] = uigetfile(filters, caption, defaultname)

[name, filepath, index] = uigetfile(filters, 'multiselect', opt...)

Inputs

filters
Optional argument specifying the preferred file filter(s) or the default file name. If a file name is specified, its extension will be used as the preferred file filter. File filters can also be specified using a cell array of strings with at least two columns; the first column giving the filter and the second column giving a description.
Type: string | cell
caption
Optional argument specifying the caption to be displayed for the dialog.
Type: string
defaultname
Optional argument specifying the default name of the file to pick.
Type: string
opt
Optional argument specifying if multiselection is allowed. Valid values are 'on' and 'off'. By default, multiselection is on.
Type: string

Outputs

name
Name of the selected file(s). If multiple files are selected using the Ctrl key, the output will be a cell matrix of the selected files.
Type: string | cell
filepath
Optional output giving the path to the selected file(s).
Type: string
index
Optional output giving the filter index of the selected file(s).
Type: string

Examples

String input:
name = uigetfile('test.txt')
        
Default file filter displayed in the dialog is 'txt files (*.txt)'
String input with caption and default file name
name = uigetfile('*.txt', 'Open My File', 'test.oml')

Default file filter displayed will be 'oml files (*.oml)', with additional filters of 'txt files (*.txt)' and 'All files (*.*)' and caption of 'Open My File'
Cell input:
[name, filepath, index] = uigetfile({'*.txt;*.dat','Text files';'*.oml','Compose files'}, 'Open My File')

Default file filter displayed in the dialog is 'Text files (*.txt;*.dat)
String input with multiple selection disabled:
name = uigetfile('test.txt', 'multiselect', 'off')

Default file filter displayed in the dialog is 'txt files (*.txt)'. Only one file
can be picked.