Script Reference : File

The File class directly provides binary disk input/output services, and it indirectly supports text files.

Data Members
Name Type Description
name string Full file name. Read only.
ok bool Stream status. Read only. False is in case if is not exist.

 

Constructors
Name Description
File(string filename [,string mode="r"]) Constructs a File object from a full file path. Where mode is:
r Open existing file in read only mode
r+ Open existing file for read write
w Create file.
ra+ Open existing file for appending. Method is equal to open existing file and moving file pointer to the end of the file.

 

Methods
Name Return Type Description
int GetSize() int Obtains the current logical length of the file in bytes.
int size() int Same as GetSize.
int Seek(int pos [,mode="s"]) int Repositions the file pointer in an open file. Where mode could be:
s - Seek from the start of the file. This is the default value.
c - Seek from the current location of the file pointer.
e - Seek from the end of the file.
Return value is the position of the file pointer if the method was successful.
int GetPos() int Return value is the position of the file pointer if the method was successful.
Read(string type,[size]) int/float/string Reads a number from the stream according to the type parameter. type can have the following values:
i8 8 bit signed integer
i16 16 bit signed integer
i32 32 bit signed integer
u8 8 bit unsigned integer
u16 16 bit unsigned integer
u32 32 bit unsigned integer
f 32 bit float
f32 32 bit float
f64 64 bit double
s ANSI string. String is readed from current position till end of the line.
sa ANSI string. When optional size is set, function reads required number of characters. If size is not defined, function reads till end of the line.
sw Unicode string. Meaning of size is the same as for sa.
   
bool Write( data,string type) bool Writes data to the file. Type is same as in Read method.
bool SetSize(int size) bool Call this function to change the length of the file.
bool CopyTo(File [,int size]) bool Method copies data to another file starting from current position. In case if size is not specified all bytes from current position to the end of file will be copied.

 

Sample 1:

{
 local f=File("c:/temp/file.txt","w");
 if(f.ok){
  for(local i=0;i<10;i++)
    f.Write("test text\r\n","sa");
 }
}

Sample 2:

 local f=File("z:/dopus.txt","ra+");
 if(!f.ok){
 f=File("z:/dopus.txt","w");
 if(f.ok){
   for(local i=0;i<10;i++) {
        f.Write("test text\r\n","sa");
   }}
}

See also: File functions