Open File Dialog Box

The openfile command displays the open file dialog box and prints the selected file path. It's syntax is as follows:

openfile [<title>="Open" [<startupdir>=<current_directory> [<filter>="*.*" [<errormsg>="" [<isforwardslash>="true"]]]]]

The "title" is the title of the open file dialog box. It's default value is "Open".

The "startupdir" is the initial directory which will be shown in the open file dialog box. By default the current working directory is shown as the initial directory. If "startupdir" includes a file name, the file will be selected. The specified path should have forward slash '/' as the path separator and not the backward slash.

The "filter" specifies the file extensions. Only files that match the given filter are shown. If you want multiple filters, separate them with ';;', for example:
"Images (*.png *.gif *.jpg);;Text files (*.txt);;XML files (*.xml)"

The "errormsg" is the message printed when the user closes the open file dialog box without selecting any file. By default no error message is displayed.

The "isforwardslash" specifies the path separator of the file path which will be printed on screen. It can have values "true" or "false". By default forward slash is used as a path separator. If "false" is specified the backward slash '\' is used as a path separator.

Note: The parameters "title", "startupdir", "filter" and "errormsg" may be empty strings (""). In this case, the default values are used.

Example: openfile "Open Text Files and Images" D:/ "Text Files (*.txt);;Images(*.jpg *.gif)" "No file selected" false

The above command displays an open file dialog box with title "Open Text Files and Images". The initial directory is set to D:\ drive. The user can select the files with extension ".txt", ".gif" or ".jpg" and the first specified filter i.e Text Files (*.txt) is selected by default. "No file selected" is the error message shown if user does not select any file and the output i.e. the file path is printed with backward slash '\' as the path separator.

Note that the arguments which contain spaces are enclosed within a pair of double quotes.


Documentation Index Page