OpenFile

InstallShield 2022 » InstallScript Language Reference

The OpenFile function opens an existing text file or binary file. Before you open the file you must set the file mode by calling OpenFileMode.

Tip:Note the following:

After you open a text file, call GetLine and WriteLine to read from and write to the file. When you finish reading from or writing to a file with GetLine or WriteLine, you must close the file using the CloseFile function.
After you open a binary file, call ReadBytes and WriteBytes to read from and write to the file.
You can use SeekBytes to position the file pointer before writing to a binary file.
You can also search, read from, and write to text files using the FileGrep, FileInsertLine, and FileDeleteLine functions. However, these functions do not require you to open or close the files (this is handled internally).
Use CreateFile to create a file. CreateFile leaves the new file open in append mode (text files) or read/write mode (binary files).

Syntax

OpenFile ( nvFileHandle, szPath, szFileName );

Parameters

OpenFile Parameters

Parameter

Description

nvFileHandle

Returns the file handle of the file that was opened. Use this handle to identify the file when you call other file-related InstallScript functions.

szPath

Specifies the path—which may include a drive designation—of the file you want to open. You can specify a valid Uniform Resource Locator (URL) in this parameter, after setting the file mode to FILE_MODE_NORMAL or FILE_MODE_BINARYREADONLY (by calling OpenFileMode). If you pass a CGI or ASP request (for example, "http://www.mydomain.net/login.asp?name=Me&pwd=wow"), the response is sent to memory and can be read by ReadBytes. To check the validity of a URL, call Is(VALID_PATH, szURL). If you pass a null string ("") in this parameter, the function fails.

szFileName

Specifies the unqualified name—that is, without a drive designation or path—of the file you want to open. If you pass a null string ("") in this parameter, the function fails.

Return Values

OpenFile Return Values

Return Value

Description

0

Indicates that the function successfully opened the file.

< 0

Indicates that the function was unable to open the file.

See Also