SelectDirEx Example

InstallShield 2019 » InstallScript Language Reference

Project • This information applies to the following project types:

InstallScript
InstallScript MSI

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

*

* InstallShield Example Script

*

* Demonstrates the SelectDirEx function.

*

* This sample script calls SelectDirEx 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 SelectDirEx dialog is displayed

* again.

*

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

 

#include "ifx.h"

 

function OnBegin()

   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 SelectDirEx dialog.

      svDir = TARGETDIR;

      

      // Set the title to display in the SelectDirEx dialog.

      szTitle =  "SelectDirEx Example";

      

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

      szMsg   = "Please choose an existing folder.";

 

      // Get an existing folder name from the user.

      nResult = (SelectDirEx (szTitle, szMsg, "", "",

         BIF_RETURNONLYFSDIRS | BIF_EDITBOX, svDir ) < 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;