Bookshelf Home | Contents | Index | Search | PDF |
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:
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
Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference Published: 18 April 2003 |