openFiles

Displays a file dialog window to let the user select a list of file paths on the local file system.

Syntax

ui.Interface.frontCall("standard", "openFiles",
 [path,name,wildcards,caption],
 [result])
  1. path - The default path of a directory like "/tmp".
  2. name - The label to be displayed for the file types / wildcards.
  3. wildcards - A space-separated list of wildcards (for example: "*.pdf" or "README* test*.txt")
  4. caption - The caption to be displayed.
  5. result - The list of selected file paths as a JSON array (or NULL if canceled).

Usage

When invoking the "openFiles" front call, the front-end displays a file dialog window, to let the end user select several file paths from the local file system.

Note: The file dialog window rendering and features depend on the type of front end and the type of the front end platform (desktop OS, web browser).

This front call is typically used to let the end user select several files that will be processed by the application.

Important: With the GBC front-end in a web browser, the path parameter is ignored, and wildcards can only hold one type of file extension.
When the file dialog is validated, the result variable contains a JSON formatted string representing an array of file paths:
["/my/first/path",  "/my/second/path",  "/my/third/path"]

The resulting string can then be converted to a DYNAMIC ARRAY OF STRING with the util.JSON.parse() method.

Note: The order of the paths in the result variable can differ from the selection order of the user.

If the user cancels the dialog, the front call returns an empty JSON array ([]) in the result variable.

Tip: When specifying a file path, pay attention to platform specific rules regarding directory separators and space characters in file names. When the front-end executes on a recent Microsoft™ Windows™ system, you can use the / slash character as directory separator, like on Unix systems. A directory or file name can contain spaces, and there is no need to surround the path with double quotes in such case. When using backslash directory separators, make sure to escape backslash characters in string literals with \\.

Example

IMPORT util
MAIN
    DEFINE rec RECORD
                path STRING,
                name STRING,
                wildcards STRING,
                caption STRING
           END RECORD
    DEFINE result STRING
    DEFINE files DYNAMIC ARRAY OF STRING
    DEFINE x INTEGER

    LET rec.path = "/tmp"
    LET rec.name = "Image files"
    LET rec.wildcards = "*.jpg *.png"
    LET rec.caption = "Select files"
    CALL ui.Interface.frontCall("standard","openFiles",[rec.*],[result])

    CALL util.JSON.parse( result, files )

    FOR x=1 TO files.getLength()
        DISPLAY SFMT("File %1: %2 ", x, files[x])
    END FOR

END MAIN