Nested while Example
InstallShield 2026 » 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.
/* This script illustrates a nested while loop.
* It searches for the specified type of files and
* shows the number of lines in each file. */
#define SOURCEDIR "c:\\example";
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_Nested while(HWND);
function ExFn_Nested while(hMSI)
LIST listID;
STRING svTarget, svResult, filename, svLine, szPath, szFileName;
NUMBER nResult, nOp,nFileHandle,count;
begin
count = 0;
nOp = RESET;
svTarget = SOURCEDIR;
listID = ListCreate (STRINGLIST);
while FindAllFiles (svTarget, "*.txt", svResult, nOp) = 0;
// To get the name of the file in the fully specified path
StrGetTokens(listID,svResult,"\\");
ListCurrentString(listID,filename);
// Set the file mode to normal.
OpenFileMode(FILE_MODE_NORMAL);
szFileName = filename;
szPath = svTarget;
// The following opens the file for editing.
OpenFile(nFileHandle, szPath, szFileName);
/*------------------------------------------------------------------*\
*
* The following retrieves each line of text from the open file and increments
* a count to find the number of lines.
*
\*------------------------------------------------------------------*/
while (GetLine (nFileHandle, svLine) = 0)
count = count + 1;
endwhile;
SprintfBox(INFORMATION,"The Total lines in the file",
"The No. of lines in the file %s is %d",filename,count);
count = 0;
// The following closes the file
CloseFile(nFileHandle);
// Continue searching files where last file was left off
nOp = CONTINUE;
if (FindAllFiles (svTarget, "*.txt", svResult, nOp) < 0) then
abort;
endif;
endwhile;
end;