OpenFileMode

InstallShield 2018 » InstallScript Language Reference

The OpenFileMode function sets the mode of the file you want to open or create. The argument you pass as the parameter nMode sets the file mode to one of the following:

ANSI or Unicode text file in append mode.
ANSI or Unicode text file in read-only mode.
Binary file in read/write mode.
Binary file in read-only mode.

After you set the file mode, call OpenFile to open an existing file or CreateFile to create and open a new file.

Syntax

OpenFileMode ( nMode );

Parameters

OpenFileMode Parameters

Parameter

Description

nMode

Specifies which mode to use to open a file. Pass one of the following predefined constants in this parameter:

FILE_MODE_APPEND—This constant allows a text file to be opened or created in append mode. When a file is opened in append mode using OpenFile, the file pointer is at the end of the file. You can use the WriteLine function to append lines to the end of the file. Files created using CreateFile are new (empty), so lines appended to the files are written at the beginning of the files. Note that if you open a file in append mode, the GetLine function will fail if you call it because the file pointer is at the end of the file.
FILE_MODE_APPEND_UNICODE—Indicates that CreateFile should create new files as Unicode files, instead of the default of ANSI. This option does not affect how existing files are opened. Existing files are always opened and saved in the existing format. To convert a file from one type to another, use the ListReadFromFile and ListWriteToFileEx with the appropriate nOptions.
FILE_MODE_NORMAL—This constant allows a text file to be opened in read-only mode. When a file is opened in read-only mode using OpenFile, the file pointer is at the beginning of the file. You can use the GetLine function to read from the file. Files created using CreateFile when FILE_MODE_NORMAL is in effect will actually be created in FILE_MODE_APPEND mode.
FILE_MODE_BINARY—This constant allows a binary file to be opened and created in read/write mode. When you open or create a file in binary mode with OpenFile or CreateFile, you can call ReadBytes to read from the file and WriteBytes to write to the file. Writing to a binary file begins at the current file pointer position, which for a newly opened or created file is position 0—the beginning of the file. If you want to append to an existing binary file opened using OpenFile, you must use SeekBytes to position the file pointer before writing. To open a file on a CD-ROM or on a read-only drive, call OpenFileMode to set the file mode to read-only (FILE_MODE_BINARYREADONLY).
FILE_MODE_BINARYREADONLY—This constant is just like the constant FILE_MODE_BINARY, except that it opens the binary file in read-only mode. When opening a binary file on CD-ROM or read-only drives, use this constant to open a binary file. FILE_MODE_BINARY will fail opening binary files on CD-ROM or read-only drives.

Return Values

OpenFileMode Return Values

Return Value

Description

0

Indicates that the function successfully set the file mode.

< 0

Indicates that the function was unable to set the file mode.

See Also