Clib Reopen File Method
The Clib Reopen File method closes the file associated with a file pointer. It then opens a file and associates it with the file pointer of the file that it closed. You can use it to redirect one of the predefined file handles to a file or from a file. These file handles include stdout, stderr, and stdin. It returns one of the following values:
If successful, then it returns a copy of the old file pointer.
If not successful, then it returns the following value:
Null
Format
Clib.freopen(filename, mode, oldFilePointer,bUseBOM)
The following table describes the arguments for the Clib Reopen File method.
Argument | Description |
---|---|
filename |
The name of the file that this method opens. |
mode |
One of the file modes specified in Clib Open File method. For Unicode, you can use the same u flag that you can use in the Clib Open File method. |
oldFilePointer |
The file pointer to the file that the Clib Reopen File method closes and where it associates the file that you specify in the filename argument. |
bUseBOM |
true: Add the Byte Order Mark (BOM) to the file. false: Do not add the Byte Order Mark (BOM) to the file. |
Because some systems expect text files without the Byte Order Mark (BOM) included in the file, a new parameter will prevent the inclusion of a BOM in a file. Previously all text files written to from Siebel eScript included the BOM in the file as a default.
Clib.freopen(filename, mode, oldFilePointer, bUseBOM)
Default value of bUseBOM is true which will, when writing the file, write the byte order mark to the file.
If a byte order mark is not required in the file, then the third parameter should have the value “false”.
For example, here the file pointer oFile has previously been created in the script and points to the secondfile.txt file.
Clib.freopen("c:\\temp\\secondfile.txt", "w", oFile, true);
Example
The following example uses the same file pointer to write to two different files:
var oFile = Clib.fopen("c:\\temp\\firstfile","w");
if (oFile == null)
{
TheApplication().RaiseErrorText("File not found.");
}
Clib.fprintf(oFile, "Writing to first file\n");
Clib.freopen("c:\\temp\\secondfile", "w", oFile);
if (oFile == null)
{
TheApplication().RaiseErrorText("File not found.");
}
Clib.fprintf(oFile, "Writing to second file\n");
Clib.fclose(oFile);
For more information, see the following topics: