CreateFile

InstallShield 2024 » InstallScript Language Reference

The CreateFile function creates a new file. If a file with the same name exists, CreateFile overwrites it. Before you create a file with CreateFile, you must set the file mode with OpenFileMode.

CreateFile leaves the newly created file open in read/write (binary file) or append (text file) mode so you can read from or write to the file using other functions such as GetLine, ReadBytes, WriteLine, and WriteBytes. To write to an existing file, you must first open the file in FILE_MODE_APPEND mode using the OpenFileMode and OpenFile functions.

Note:In addition to read/write or append mode, all newly created files automatically open in OF_SHARE_DENY_NONE mode. This means that the files are opened without denying other programs read or write access to the files. This mode has its roots in the Windows API OpenFile.

When you finish reading from and writing to a file, you must close the file using the CloseFile function.

Syntax

CreateFile ( nvFileHandle, szPath, szFileName );

Parameters

CreateFile Parameters

Parameter

Description

nvFileHandle

Returns the handle of the new file.

szPath

Specifies the fully qualified path of the subdirectory in which to create the new file.

Note:CreateFile fails if the folder specified in szPath does not exist. You can test for the existence of a folder by calling ExistsDir and create a folder by calling CreateDir.

szFileName

Specifies the name of the file to create.

Return Values

Return Values

Return Value

Description

0

Indicates that the function successfully created the new file.

< 0

Indicates that the function was unable to create the specified file.

Additional Information

The actions of the CreateFile function are not logged for uninstallation when logging is enabled. If you want a file that is created by CreateFile to be logged for uninstallation, transfer a starter file with the file name you want to the target system using XCopyFile while logging is enabled. You enable and disable logging with the Enable and Disable functions. XCopyFile actions are logged when logging is enabled, so the starter file is logged for uninstallation. After transferring the logged starter file, you can write to or overwrite the logged starter file using CreateFile and other file-related functions. The file name must remain unchanged; otherwise, it is not found during uninstallation.

See Also