The function append_to_file will append a line to an existing file. If the file does not exist it will create a new file.
remstart
---------------------------------------------------------------------------------
(C) 2015, Atilla
Test for function append_to file
---------------------------------------------------------------------------------
remend
set window on
set display mode 800,600,32
set window size 800,600
cls
append_to_file(\"test.txt\",1,\"My First Record\")
append_to_file(\"test.txt\",1,\"My 2nd Record\")
for h=3 to 10
append_to_file(\"test.txt\",1,\"My \"+str$(h)+\"th Record\")
next h
`suspend for key
end
`---------------------------------------------------------------------------------
function append_to_file(Filename$,FileNumber,Text$)
`
` (C) 2015 - Attila
`
` The function appends a line at the end of a file. If the file does not
` exist it will create a new file
`---------------------------------------------------------------------------------
if file exist(Filename$) = 0
open to write FileNumber, Filename$
write string FileNumber, Text$
close file FileNumber
else
if file exist(FileName$+\"_save\") then delete file FileName$+\"_save\"
rename file FileName$, FileName$+\"_save\"
FNr2=FileNumber+1
open to read FNr2, FileName$+\"_save\"
open to write FileNumber, Filename$
while not file end(FNr2)
read string FNr2, Tmp$
write string FileNumber, Tmp$
endwhile
write string FileNumber, Text$
close file FileNumber
close file FNr2
if file exist(FileName$+\"_save\") then delete file FileName$+\"_save\"
endif
endfunction