CopyFile Example

InstallShield 2022 ยป InstallScript Language Reference

Note:To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

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

*

* InstallShield Example Script

*

* Demonstrates the CopyFile function.

*

* This script copies files in the directory specified by

* SOURCE_DIR to the directory specified by TARGET_DIR.

*

* Note: Before running this script, you must set the

*       preprocessor constants to existing paths on

*       the target system.

*

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

 

#define  SOURCE_DIR "C:\\Source"

#define  TARGET_DIR "C:\\Target"

 

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

#include "Ifx.h"

 

export prototype ExFn_CopyFile(HWND);

 

function ExFn_CopyFile(hMSI)

    NUMBER nResult;

begin

    

    // Copy all files in the source directory, including files

    // in subdirectories, to the target directory.

    nResult = CopyFile(SOURCE_DIR ^ "*.*", TARGET_DIR ^ "*.*");

    

    // Report the results of the copy operation.

    switch (nResult)

        case 0:

            MessageBox ("Files successfully copied.", INFORMATION);

        case COPY_ERR_CREATEDIR:

            MessageBox ("A target directory could not be created.", SEVERE);

        case COPY_ERR_MEMORY:

            MessageBox ("Insufficient memory.", SEVERE);

        case COPY_ERR_NODISKSPACE:

            MessageBox ("Insufficint disk space.", SEVERE);

        case COPY_ERR_OPENINPUT:

            MessageBox ("Unable to open the input files in "+ SOURCE_DIR +".",

                       SEVERE);

        case COPY_ERR_OPENOUTPUT:

            MessageBox ("Unable to copy the source files.", SEVERE);

        case COPY_ERR_TARGETREADONLY:

            MessageBox ("A target file already exists and cannot be overwritten.",

                       SEVERE);

        default:

            MessageBox ("An unspecified error occurred.", SEVERE);

    endswitch;

 

end;