File Object

eSignal EFS 2

File Object

Top  Previous  Next

 

File Object

 

The File Object allows EFS scripts to read/write files. All files created, read or written using the File object will be read from the eSignal Formula Output folder.

 

 

Note: you can view/change the location of the Formula Output folder from within the eSignal program. Click on Tools-->EFS-->Settings to pull up the Formula Engine Settings window.

 

 

File Methods

 

close()

closes an open file

eof()

boolean. checks for end-of-file condition

exists()

boolean. checks for the existence of a file

flush()

writes the contents of the internal buffer to file

getLength()

returns the length of a file

getPosition()

returns the current position of the pointer in an open file. the first byte of the file is 0

isOpen()

boolean. returns true if the file is open

mkDir(sDir)

boolean. creates sDir and returns true if successful

open(sMode)

boolean. opens the file in sMode and returns true if successful

read(nBytes)

reads nBytes of data from the file into a string

readln()

reads the current line from an open file and returns a string. line separator characters ("\n", "\r") are not included in the string

setPosition(nBytes)

positions a pointer to nBytes in an open file

write(sString)

boolean. writes sString to an open file

writeln(sString)

boolean. writes sString along with a carriage return to an open file

 

Mode Values

 

rt

opens a file for reading. If the file exists, the method succeeds and returns true; otherwise, the method fails and returns false.

wt

opens a file for writing. If the file does not already exist, it is created; otherwise, it is overwritten. This method always succeeds and returns true.

at

opens a file for appending (writing at the end of the file). If the file does not already exist, it is created. This method always succeeds and returns true.

rt+

opens a file for reading and writing. If the file exists, the method succeeds and returns true; otherwise, the method fails and returns false. Reading and writing commence at the beginning of the file. When writing, characters at the beginning of the file are overwritten.

wt+

opens a file for reading and writing. If the file does not already exist, it is created; otherwise, it is overwritten. This method always succeeds and returns true.

at+

opens a file for reading and appending. If the file does not already exist, it is created. This method always succeeds and returns true. Reading and appending commence at the end of the file.

 

 

Usage

 

//read a file

var f = new File( "TestFolder/testReadWrite.txt" );

if( f.exists() ) {

       f.open( "rt" );

       var line;

       while( !f.eof() ) {

               line = f.readln();

               debugPrintln( "Line: [" + line + "]" );

       }

       f.close();

}

 

//create a directory

var f = new File( "TestFolder" );

f.mkDir();

 

 

 

getFormulaOutputRoot()