DeleteFile Example

InstallShield 2015 ยป 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 DeleteFile function.

*

* First, DeleteFile is called to delete a specified file from a

* directory.  Then it is called again to delete all files with

* the extention "sys" from the same directory.

*

* Note: Before running this script, create a directory named

*       ISExampl in the root of drive C.  Then create a file

*       named ISExampl.txt in that directory.  Finally, create

*       two or more files with the extension "sys" in that

*       directory. These files will be deleted by the script.

*

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

 

#define DEL_DIR       "C:\\ISExampl"

#define DEL_FILE      "ISExampl.txt"

#define DEL_SYS_FILES "*.sys"

#define TITLE_TEXT    "DeleteFile example"

 

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

#include "Ifx.h"

 

export prototype ExFn_DeleteFile(HWND);

 

function ExFn_DeleteFile(hMSI)

   STRING szMsg;

begin

 

    // Delete the file specified by DEL_FILE from the target directory.

    if (DeleteFile (DEL_DIR ^ DEL_FILE) < 0) then

        MessageBox ("First call to DeleteFile failed.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE_TEXT, "%s was delete from %s.",

                        DEL_FILE, DEL_DIR);

    endif;

 

    // Delete the files specified by DEL_SYS_FILES

    // from the target directory.

    if (DeleteFile (DEL_SYS_FILES) < 0) then

        MessageBox ("Second call to DeleteFile failed.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE_TEXT,

                   "All files matching %s were delete from %s.",

                   DEL_SYS_FILES, DEL_DIR);

    endif;

 

end;