Dialog.FolderBrowse

string Dialog.FolderBrowse ( 

string Prompt,

string DefaultFolder )

Example 1

folder_path = Dialog.FolderBrowse("Select Folder", _SourceFolder);

Prompts the user to select a single folder from the "source folder" on the CD-ROM and stores the path to the selected folder in a variable named "folder_path."

Note: _SourceFolder is a built-in variable that contains the path to the folder where the setup.exe file is located.

Example 2

-- Display a folder browse dialog
storage_path = Dialog.FolderBrowse("Store Files In", _ProgramFilesFolder);

-- If CANCEL was not chosen, then let's get the folder path
if (storage_path ~= "CANCEL") then
    Dialog.Message("You chose the following folder", storage_path);
end

Asks the user what path to store files in, letting them browse for a folder starting from the Program Files folder. The resulting path is stored in storage_path. The second block of code is a check to see if the user pressed the cancel button. If they didn't, a dialog message is displaying showing the folder that was selected.

Note: _ProgramFilesFolder is a built-in variable that contains the path to the user's Program Files folder.

Example 3

-- Allow the user to select a directory to unzip the files.
target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");


-- Check to see if the user cancelled or an error occurred.
if (target_folder ~= "CANCEL") and (target_folder ~= "") then
    -- Gets a list of the contents of a zip file.
    zip_contents = Zip.GetContents(_SourceFolder.."\\Info.zip", true);

    -- Get the error code of the last action.
    error = Application.GetLastError();

    -- If an error occurred, display the error code message.
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    else
        -- Take the table and turn it into a string with newlines for displaying.
        zip_contents_display = Table.Concat(zip_contents, "\r\n", 1, TABLE_ALL);

        -- Ask the user if they are sure they would like to unzip the contents.
        result = Dialog.Message("Information", "The following files will be unzipped:\r\nClick the Cancel button to abort the process.\r\n\r\n"..zip_contents_display, MB_OKCANCEL)

        -- If the user clicked Ok, unzip the files.
        if (result == IDOK) then
            -- Show the status dialog.
            StatusDlg.Show();
            -- Extract the contents of the Zip file.
            Zip.Extract(_SourceFolder.."\\Info.zip", {"*.*"}, target_folder, true, true, "", ZIP_OVERWRITE_NEVER, nil);

            -- Check the error code for the last action.
            error = Application.GetLastError();

            -- Hide the status dialog.
            StatusDlg.Hide();

            -- If an error occurred, display the error code message.
            if (error ~= 0) then
                Dialog.Message("Errror", tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
            else
                Dialog.Message("Success", "The unzipping was successful.", MB_OK, MB_ICONINFORMATION);
            end
        end
    end
end

This example first prompts the user to select a folder using the Dialog.FolderBrowse action. This folder will be used to unzip the files to. The user is then presented with a dialog containing the names of the files that will be unzipped and allows them to abort the process. If the user clicks OK, the files are unzipped to the folder they selected. Notification will be given at the end of the process as to whether or not the procedure was successful.

See also:  Related Actions