Siebel eScript Language Reference > C Language Library Reference > Clib File and Directory Methods >

Clib Open File Method


The Clib Open File method opens the file that you specify in the filename argument. It opens it in the mode that you specify in the mode argument. It returns one of the following values:

  • If successful, then it returns a file pointer to the file that it opened.
  • If not successful, then it returns the following value:

    Null

If this method successfully opens a file, then it clears the error status for this file and initializes a buffer for automatic buffering of read and write activity with the file.

Several Clib methods require an argument named filePointer. It is often the return value of a Clib Open File call.

Format

Clib.fopen(filename, mode)

Table 126 describes the arguments for the Clib Open File method.

Table 126. Arguments for the Clib Open File Method
Argument
Description

filename

Any valid file name that does not include a wildcard character.

mode

One of the required characters that specify a file mode followed by optional characters. For more information, see Usage for the Mode Argument.

Usage for the Mode Argument

Table 127 describes usage for the mode argument. The mode argument is a string that includes one of the following required characters, and then followed by other optional characters:

  • r
  • w
  • a
Table 127. Usage for the Mode Argument of the Clib Open File Method

Argument

Mode

Required

r

Opens the file for reading. The file must already exist.

Yes. You must include one of these arguments.

w

Opens the file for writing. If the file does not exist, then Siebel eScript creates the file.

a

Opens the file in append mode.

b

Opens the file in binary mode. If you do not specify b, then this method opens the file in text mode and performs an end-of-line translation.

No

t

Opens the file in text mode. For a non-ASCII character:

  • You use the u argument.
  • You do not use the t argument.

No

u

Opens the file in Unicode mode as UTF-16 or Little Endian. For example:

Clib.fopen("filename.txt", "rwu")

You can use the u mode for ASCII and non-ASCII characters.

No

+

Opens the file for reading and writing.

No

Example 1

The following example opens the ReadMe text file for text mode reading and displays each line in that file:

var fp:File = Clib.fopen("ReadMe","rt");
if ( fp == null )
   TheApplication().RaiseErrorText("\aError opening file for reading.\n")
else
{
   while ( null != (line=Clib.fgets(fp)) )
   {
      Clib.fputs(line, stdout)
   }
}
Clib.fclose(fp);

Example 2

The following example opens a file, writes a string to that file, and then uses the default codepage to read the string from this file:

var oFile = Clib.fopen("myfile","rw");
if (null != oFile)
{
   var sHello = "Hello";
   var nLen = sHello.length;
   Clib.fputs(sHello, oFile);
   Clib.rewind(oFile);
   Clib.fgets (nLen, sHello);
}

Example 3

The following example opens a file, writes a string to this file, then uses Unicode to read the string from this file:

var oFile = Clib.fopen("myfile","rwu");
if (null != oFile)
{
   var sHello = "Hello";
   var nLen = sHello.length;
   Clib.fputs(sHello, oFile);
   Clib.rewind(oFile);
   Clib.fgets (nLen, sHello);
}

Example 4

The following example specifies a file path:

function WebApplet_ShowControl (ControlName, Property, Mode, &HTML)
{
if (ControlName == "GotoUrl")
   {
      var fp = Clib.fopen("c:\\test.txt","wt+");
      Clib.fputs("property = " + Property + "\n", fp);
      Clib.fputs("mode = " + Mode + "\n",fp);
      Clib.fputs("ORG HTML = " + HTML + "\n",fp);
      Clib.fclose(fp);
      HTML = "<td>New HTML code</td>";
   }
return(ContinueOperation);

Related Topics

For more information, see the following topics:

Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.