UOX3 Script Engine

Functions, Methods, Properties and Event handling

File I/O Methods

 

Open
Prototype
Open( string filename, string accessMethod, string subFolder );
PurposeOpens a file for reading, writing or appending.
NotesaccessMethod is a one byte string, which contains either "a" (append), "r" (read) or "w" (write). Subfolder is a subfolder under UOX3/shared/, which will be created if it doesn't exist.
Example of Usage
var mFile = new UOXCFile;
mFile.Open( "test.dat", "a", "subFolder" );

 

Close
Prototype
Close();
PurposeCloses a file that is currently open.
NotesClosing an unopened file is undefined.
Example of Usage
mFile.Close();

 

Write
Prototype
Write( string toWrite );
PurposeWrites a string out to the file.
NotesA file cannot be longer than 1MB in size. If opened for reading, this will not work.
Example of Usage
mFile.Write( "Hello cruel world\n" );

 

Read
Prototype
string Read( int numBytes );
PurposeReturns a string of length numBytes, reading numBytes from the opened file.
NotesnumBytes must be at least 1 and less than or equal to 512.
Example of Usage
var mLine = mFile.Read( 80 );

 

ReadUntil
Prototype
string ReadUntil( string delimeter );
PurposeReads a string until it encounters a newline or the string specified by delimeter.
Notesdelimiter is at most a 2 character string (for C style character escapes, where \n is a newline, \' is a quote and so on).
Will not read more than 512 bytes.
Example of Usage
var untilT = mFile.ReadUntil( "t" );
// reads a line until it hits the letter t, a newline, or 512 bytes in length.

 

Length
Prototype
int Length();
PurposeReturns the length of the file
Example of Usage
var fileLength = mFile.Length();

 

Pos
Prototype
int Pos();
PurposeReturns or sets the position we are at in the file
NotesThe current position that you are at in the file. This can be read and set, where setting it moves relative to the start of file (i.e. if you set it to 5, it would be 5 bytes from the start, not 5 bytes from it's current location). You cannot seek a location if you have opened the file for append.
Example of Usage
var filePos = mFile.Pos();

 

EOF
Prototype
bool EOF();
PurposeA boolean value returning true if the file pointer is at the end of the file.
Example of Usage
while( !mFileRead.EOF() ) { ... }

 

Free
Prototype
bool Free()
PurposeDeallocates the memory associated with creating the variable.
NotesThis must be called otherwise a slow memory leak will occur.
Example of Usage
mFile.Free();

 

DeleteFile
Prototype
bool DeleteFile( fileName(, subFolderName ))
PurposeDeletes a specified file, either in root of shared folder, or inside a subfolder.
NotesFile and subfolder names cannot contain some characters such as forward or backwards slashes, double dots, etc.
Example of Usage
var fileName = "myFile.jsdata";
var folderName = "mySubFolder";
DeleteFile( fileName, folderName );

 

©Copyright 2000-2001 WWW.UOX3.NET (Daniel Stratton/Matthew Randall)