ファイルを読む。(バージョン4.48以降)
fileread <file handle> <read byte> <strvar>
<file handle> により指定されたファイルから特定したバイト数のデータを読み出す。
データは文字列変数 <strvar> へ記憶され、ファイルポインタは読み込んだバイト数分進められる。
データを読み込み終わる前にファイルポインタがファイルの終わりまで行った場合は、システム変数 "result" に 1 が格納される。 それ以外は、"result" に 0 が格納される。
変数 <read byte> のとる値の範囲は 1 から 511 でなければならない。
filename = 'foo.txt' fileopen fp filename 0 :loop fileread fp 10 data messagebox data filename if result goto fclose goto loop :fclose fileclose fp
; バイナリファイルの先頭から32バイトを読み込み、ホストへ送信する。
filename = 'sample.bin'
fileopen fhandle filename 0
if fhandle == -1 goto the_end
call send_16_bytes ; send first 16 bytes
fileseek fhandle 16 1 ; seek past next 16 without sending
call send_16_bytes ; send next (last) 16 bytes
fileclose fhandle
goto the_end
;#########################################
:send_16_bytes
for i 1 16
fileread fhandle 1 str ; read one byte at a time so we can detect zero.
if result == 1 break
str2code integer str ; if zero then str will be empty and integer will be set to zero
;sprintf 'integer = 0x%02X' integer
;messagebox inputstr 'test'
send integer
next
return
;#########################################
:the_end