Script Reference : File
The File class directly provides binary disk input/output services, and it indirectly supports text files.
| Name | Type | Description |
|---|---|---|
| name | string | Full file name. Read only. |
| ok | bool | Stream status. Read only. False is in case if is not exist. |
| Name | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| File(string filename [,string mode="r"]) | Constructs a File object from a full file path. Where mode
is:
|
| 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:
|
||||||||||||||||||||||||||
| 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
