From Scriptwiki
Jump to: navigation, search

Returns information about an open file.

$fopen(name | N)

$fopen has the following properties:

Property Meaning
fname returns the full path and file name assigned to the specified name / number.
pos returns the position of the pointer (after what byte it is).
eof returns 1 if end of file is reached, else 0.
err returns 1 if an error occurred, else 0.

Note that the .eof and .err properties should be checked after each file access command or identifier, since file access errors will not halt a script.


We have the following file called moo.txt in our mircdir:


At first, we open it using fopen moo moo.txt.

echo -a $fopen(moo).fname

This would return C:\program\mIRC\moo.txt if your mIRC is installed to C:\program, else the path to your mIRC installation (it is the same as $mircdir $+ moo.txt).

echo -a $fopen(moo).err

This example returns 0 as no error occurred.

; echo the current position of the pointer
echo -a $fopen(moo).pos
; this would echo 0, as it is at the begin of the file
; now let's read a line to move the pointer
echo -a $fread(moo)
; echo the new position of the pointer
echo -a $fopen(moo).pos
; as the pointer was moved, it will now return 5 (it was moved 5 bytes)
; the first three bytes are obvious (o, n, e), then there is a $cr, at the end of the line a $lf