
Description
Closes file specified by a file ID argument

Syntax
ret = close(filehandle)

Parameters
| filehandle | : | File number Default: all file numbers that are currently open |

Return Value

System Return Value
ERROR
| 0 | | Success |
| 5 | | File number error |

Example
make_newfile()
exit
function make_newfile()
local fno
fno = open('foge.txt', new)
print('hello world', fno)
close(fno)
endfunction

Description
Flush the disk cache without closing the file.
A specified file must be opened in read mode
Normally, this function is not used

Syntax
ret = flush(filehandle)

Parameters

Return Value

System Return Value
ERROR
| 0 | | Success |
| 1 | | Argument error |
| 5 | | File number error |

Example
//[result example]
//
// 1 : hello world
// 2 : foge
// 3 : foo
// 4 : goo
// 5 : boo
//
get_fileline_to_flush()
exit
function get_fileline_to_flush()
local i
local lineString = ''
local fno
fno = open('foo.txt', read)
loop i=1; ; i++
lineString = readline(fno)
if ERROR != 0
break
endif
print('${i} : ${lineString}', STDOUT)
flush(STDOUT)
endloop
close(fno)
endfunction

Description
Opens file
The returned value of file ID is used in the following functions of filehandles
If file is open in write mode, the output file will be the opened file as default.

Syntax
ret = open(filename,mode)

Parameters
| filename | : | File name to open |
| mode | : | Mode to open a file Default: NEW You can specify NEW, APPEND, and READ which are defined as system variable. |

Return Value
| positive integral number | : | File number | |
| 0 | : | Error | |

System Return Value
ERROR
| 0 | | Success |
| 1 | | Argument error |
| 4 | | OPEN error |
| 7 | | SEEK error |

See Also

Example
make_newfile()
exit
function make_newfile()
local fno
fno = open('foge.txt', new)
print('hello world', fno)
close(fno)
endfunction

Description
Sets and changes the default of output file
A specified file must be open in write mode

Syntax
ret = output(filehandle)

Parameters
| filehandle | : | File number Default: system variable STDOUT |

Return Value

System Return Value

Example
//[result example]
//
// [odd.txt] [even.txt]
// 1 2
// 3 4
// 5 6
// 7 8
// 9 10
//
make_newfile2()
exit
function make_newfile2()
local i
local fno
local fid
fno = open('odd.txt', new)
fid = open('even.txt', new)
loop i=1; i<=10; i++
if i % 2 == 0 /* even number */
output(fid)
else
output(fno)
endif
print('${i}')
endloop
close(fno)
close(fid)
endfunction

Description
Outputs specified character string to the file
The output file must be opened in write mode

Syntax
ret = print(string,filehandle)

Parameters
| string | : | character string to be printed |
| filehandle | : | File number Default: system variable STDOUT You can specify STDOUT, STDERR, and STDLOG which are defined as system variable. |

Return Value
| NULL | : | Fail or printed character string | |
| string | : | Printed character string | |

System Return Value
ERROR
| 0 | | Success |
| 1 | | Argument error |
| 2 | | Output error |
| 5 | | File number error |

See Also

Example
//[result example]
//
// Hello
// World !
// ********************
// HelloWorld !
//
make_newfile3()
exit
function make_newfile3()
local fno
fno = open('boo.txt', new)
print('Hello', fno)
print('World !', fno)
print('********************', fno)
printstring('Hello', fno)
printstring('World !', fno)
close(fno)
endfunction

Description
Outputs specified character string to the file
Equivalent to print, except for no line feed
The output file must be opened in write mode

Syntax
ret = printstring(string,filehandle)

Parameters
| string | : | Character string to be printed |
| filehandle | : | File number Default: system variable STDOUT You can specify STDOUT, STDERR, and STDLOG which are defined as system variable. |

Return Value
| NULL | : | Fail or printed character string | |
| string | : | Printed character string | |

System Return Value
ERROR
| 0 | | Success |
| 1 | | Argument error |
| 2 | | Output error |
| 5 | | File number error |

See Also

Example
//[result example]
//
// Hello
// World !
// ********************
// HelloWorld !
//
make_newfile3()
exit
function make_newfile3()
local fno
fno = open('boo.txt', new)
print('Hello', fno)
print('World !', fno)
print('********************', fno)
printstring('Hello', fno)
printstring('World !', fno)
close(fno)
endfunction

Description
Reads one row per line and returns it as character string.
A specified file must be opened in read mode

Syntax
ret = readline(filehandle)

Parameters

Return Value
| NULL | : | Fail or printed character string | |
| string | : | Printed character string | |

System Return Value
ERROR
| 0 | | Success |
| 1 | | Argument error |
| 5 | | File number error |
| 15 | | No character strings to read |

Example
//[result example]
//
// 1 : hello world
// 2 : foge
// 3 : foo
// 4 : goo
// 5 : boo
get_fileline()
exit
function get_fileline()
local i
local lineString = ''
local fno
fno = open('foo.txt', read)
loop i=1; ; i++
lineString = readline(fno)
if ERROR != 0
break
endif
print('${i} : ${lineString}', STDOUT)
endloop
close(fno)
endfunction