FileGrep

InstallShield 2024 » InstallScript Language Reference

The FileGrep function searches a text file for a specified string. If the string is found, the line containing that string is returned in svReturnLine and the number of the line is returned in nvLineNumber. The search is not case-sensitive. FileGrep works on line-oriented text files; it will not work with binary files.

Note:It is not necessary to open a file before searching it with FileGrep; nor do you need to close it after the call to FileGrep. File open and file close are performed automatically by FileGrep. Although FileGrep will perform successfully in most cases on a file that is already open as a result of a previous call to OpenFile, it will return FILE_NOT_FOUND if the file was opened in append mode.

Syntax

FileGrep ( szFileName, szSearchStr, svReturnLine, nvLineNumber, nFlag );

Parameters

FileGrep Parameters

Parameter

Description

szFileName

Specifies the fully qualified name of the file to search.

szSearchStr

Specifies the search string.

svReturnLine

Returns the line in which szSearchStr was found.

nvLineNumber

Return the number of the line in which szSearchStr was found. Line numbering starts at 0.

nFlag

Specifies search options. Pass one of the following predefined constants in this parameter:

CONTINUE—Retrieves the next occurrence (if any) of the search string.
RESTART—Retrieves the first instance of the search string.

Return Values

FileGrep Return Values

Return Value

Description

0

FileGrep found the specified string.

< 0

FileGrep failed because of one of the following conditions:

END_OF_FILE (-4)—The end of file was reached without finding the search string.
FILE_NOT_FOUND (-2)InstallShield was unable to find the file in szFileName.
FILE_LINE_LENGTH (-3)—The line exceeds the maximum length allowed.
OTHER_FAILURE (-1)—An unspecified error has occurred.

See Also