FileInsertLine

InstallShield 2018 » InstallScript Language Reference

The FileInsertLine function inserts or replaces a line using line numbers. You can use FileInsertLine with FileGrep, which finds lines and returns their line numbers.

FileInsertLine works on line-oriented text files with lines that are no longer than 1,024 bytes. With InstallShield, a line longer than the maximum allowed length indicates a binary file and causes FileInsertLine to fail.

Caution • The file specified by szFileName must not already have been opened by a call to OpenFile. If szFileName is already open, call CloseFile before calling FileInsertLine.

Syntax

FileInsertLine (szFileName, szInsertLine, nLineNumber, nInsertFlag);

Parameters

FileInsertLine Parameters

Parameter

Description

szFileName

Specifies the unqualified name of a file located in the directory specified by the system variable SRCDIR, or the fully qualified path to the file. The value of szInsertLine is inserted into that file if it exists.

szInsertLine

Specifies the string to insert into the file.

nLineNumber

Specifies the line number at which you want to insert szInsertLine. The first line number is 0.

nInsertFlag

Specifies an insertion location option. Pass one of the following predefined constants in this parameter:

BEFORE—Inserts the line before nLineNumber.
AFTER—Inserts the line after nLineNumber.
APPEND—Appends szInsertLine to the line indicated by nLineNumber.
REPLACE—Replaces the line indicated by nLineNumber with szInsertLine.

Return Values

FileInsertLine Return Values

Return Value

Description

0

FileInsertLine successfully inserted the line into the specified file.

< 0

FileInsertLine failed because of one of the following conditions:

FILE_LINE_LENGTH (-3)—Indicates that the length of the line exceeds the maximum length allowed for text files.
FILE_NOT_FOUND (-2)—FileInsertLine was unable to find the file in szFileName.
FILE_RD_ONLY (-5)—Indicates that the file is write-protected.
LINE_NUMBER (-7)—Indicates that one of the line numbers you specified is less than zero, or the line number does not exist in the file.
OUT_OF_DISK_SPACE (-6)—Indicates that there is insufficient space on the disk drive to complete the specified operation.
OTHER_FAILURE (-1)—An unspecified error has occurred.

See Also