SelectDir Example

InstallShield 2016 » InstallScript Language Reference

Project • This information applies to the following project types:

InstallScript
InstallScript MSI

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the SelectDir function.

*

* This script calls SelectDir to display a dialog that

* allows the user to specify a folder. If the specified folder

* does not exist, it is not created. Instead, an error message

* is displayed and the SelectDir dialog is displayed again.

*

\*--------------------------------------------------------------*/

 

#define TITLE_TEXT "SelectDir Example"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_SelectDir(HWND);

 

function ExFn_SelectDir(hMSI)

   STRING  szTitle, szMsg, svDir;

    BOOL    bCreate, bFolderExists;

    NUMBER  nResult;

begin

 

   // Loop until user cancels or selects an existing folder.

   repeat

 

      // Set a default folder for the SelectDir dialog.

      svDir = INSTALLDIR;

 

      // Set the message to display in the SelectDir dialog.

      szMsg   = "Please choose an existing folder.";

 

      // Get an existing folder name from the user. The fourth

      // parameter indicates that a non-existing folder should

      // not be created.

      nResult = (SelectDir (TITLE_TEXT, szMsg, svDir, FALSE) < 0) ;

 

      if nResult = 0 then

 

         // Determine whether the folder exists.

         bFolderExists = ExistsDir (svDir);

 

         if bFolderExists = NOTEXISTS then

            // The folder does not exist.  Ask user to select again.

            szMsg = "%s does not exist.\nPlease choose an existing folder.";

            SprintfBox  (WARNING, szTitle, szMsg, svDir);

         endif;

 

      endif;

 

   until (nResult = CANCEL) || (bFolderExists = EXISTS);

 

   if (bFolderExists = EXISTS) then

 

      // Display the name of the selected folder.

      SprintfBox (INFORMATION, szTitle, "You selected %s.", svDir);

 

   endif;

 

end;