SYS_FileOpen Function

Action

Opens a file on a target machine.

Syntax

hFile = SYS_FileOpen (sPath, fmMode [, fsShare[, ftType]])
Variable Description
hFile A handle to the opened file. HFILE.
sPath The name of the file to open. STRING.
fmMode The mode to open the file with. FILEMODE.
fsShare Optional: Specifies file-sharing behavior. FILESHARE.
ftType Optional: Specifies the format of the text file to be created. Only has an effect when creating a new file or when reading a file using the Open Agent. FILETYPE.

Notes

  • SYS_FileOpen is executed by the agent process, not the Silk Test Classic process; but it is essentially the same as FileOpen. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator.

  • SYS_FileOpen opens the file identified by sPath, or creates it, depending on the mode you specify (see below). This function returns a file handle of type HFILE, which you pass to other file functions.

  • When the agent disconnects, any open files are closed and saved, but Micro Focus recommends using SYS_FileClose() when you are finished with a file. Any open files are automatically closed and saved at the end of a test script as well.

  • ftType is used with the Open Agent when creating a new file or when reading a file, and with the Classic Agent only when creating a new file. If a byte order mark (BOM) is not included in the file to be opened, the ftType parameter determines the encoding type.

  • This function is not designed for local access.

Example

The following example checks a BOOLEAN value (presumably passed into the function/test case) to determine whether or not the file should be shared and then sets the file-sharing behavior accordingly.

[ ] // output file handle
[ ] HFILE OutputFileHandle
[ ] FILESHARE fShare
[ ] 
[ ] // check to see if file opening should lock out other writers
[-] if (bExclusiveWrite == TRUE)
	[ ] fShare = FS_DENY_WRITE 
[-] else 
	[ ] fShare = FS_DENY_NONE 
[ ] 
[ ] // now open the file 
[ ] OutputFileHandle = SYS_FileOpen ("mydata.txt", FM_WRITE, fShare)