Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object >

Clib.fopen() Method


This method opens a specified file in a specified mode.

Syntax

Clib.fopen(filename, mode)

Parameter
Description
filename
Any valid filename that does not include wildcard characters
mode
One of the following characters specifying a file mode, optionally followed by one of the characters listed in Table 9.

Returns

A file pointer to the file opened; null if the function fails.

Usage

This function opens the file filename, in mode mode. The mode parameter is a string composed of "r", "w", or "a" followed by other characters as follows:

Table 9.  File Mode Characters
Character
Mode
r
Opens the file for reading; the file must already exist
w
Opens the file for writing; the file must already exist
a
Opens the file in append mode
Optional Characters
b
Opens the file in binary mode; if b is not specified, the file is opened in text mode (end-of-line translation is performed)
t
Opens the file in text mode
u
Opens the file in Unicode mode; for example, Clib.fopen("filename.txt", "rwu")
+
Opens the file for update (reading and writing)

When a file is successfully opened, its error status is cleared and a buffer is initialized for automatic buffering of reads and writes to the file.

Example

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

var fp = 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);

Here is an example which opens a file and reads and writes a string, using the default codepage:

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);
}

Here is an example which opens a file and reads and writes a string in Unicode mode:

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);
}

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);

See Also

Clib.fclose() Method and Clib.tmpfile() Method


 Siebel eScript Language Reference 
 Published: 18 April 2003