FindAllFiles 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 FindAllFiles function.

*

* This script gets a directory name and filespec from the

* user.  Then it calls FindAllFiles repeatedly to build a

* list of files that are located in the specified directory

* and whose names match the filespec.  Finally, the list of

* matching files is displayed in a listbox.

*

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

 

#define TITLE_TEXT "FindAllFiles Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_FindAllFiles(HWND);

 

function ExFn_FindAllFiles(hMSI)

    STRING szMsg, svDir, svFileSpec, svMatchingFileName, svNumFiles;

    NUMBER nResult, nNumFiles;

    LIST   listFiles;

begin

 

selectdir:

 

    // Set up parameters for call to SelectDir.

    szMsg = "Select a directory to search.";

    svDir = "";

 

    // Select a search directory.

    SelectDir (TITLE_TEXT, szMsg, svDir, FALSE);

 

askfile:

    szMsg = "Enter a file specification to search for in " + svDir + ":";

 

    // Get a file specification from the user.

    if (AskText (szMsg , "*.*", svFileSpec) = BACK) then

        goto selectdir;

    endif;

 

    // Create a string list for the file listing.

    listFiles = ListCreate (STRINGLIST);

 

    if listFiles = LIST_NULL then

        MessageBox ("Unable to create list.", SEVERE);

        abort;

    endif;

 

    // Set the file count to zero.

    nNumFiles = 0;

 

    // Show a message while the file list is being built.

    SdShowMsg ("Searching . . . ", TRUE);

 

    // Get the first file that matches the file spec.

    nResult = FindAllFiles (svDir, svFileSpec, svMatchingFileName, RESET);

 

    while(nResult = 0)

        // Add the file to the list.

        if ListAddString (listFiles, svMatchingFileName, AFTER) < 0 then

            MessageBox ("Unable to build complete file list", WARNING);

            goto showmatches;

        endif;

 

        // Increment the file counter.

        nNumFiles = nNumFiles + 1;

 

        // Find the next matching file name.

        nResult = FindAllFiles(svDir, svFileSpec, svMatchingFileName, CONTINUE);

    endwhile;

 

showmatches:

 

    // Free all files and folders accessed by FindAllFiles. If your

    // setup does not target the Windows NT platform, this step is

    // not necessary.

    FindAllFiles(svDir, svFileSpec, svMatchingFileName, CANCEL);

 

    // Convert the file count to a string for display.

    NumToStr(svNumFiles, nNumFiles);

 

    // Clear the message that displayed while the file list was being built.

    SdShowMsg("", FALSE);

 

    // Display the files that match the file specification.

    szMsg = "Number of matching files : " + svNumFiles;

    if (SdShowInfoList(TITLE_TEXT, szMsg, listFiles) = BACK) then

        ListDestroy(listFiles);

        goto askfile;

    endif;

 

    // Remove the list from memory.

    ListDestroy(listFiles);

 

end;