Appending data to a file

Blitz3D Forums/Blitz3D Programming/Appending data to a file

_33(Posted 2008) [#1]
I'm a little behind with the handling of files in Blitz3D. How would one append data to a file? I'm making a trace system, and right now I'm doing ReadLines to get to the end of the file so I can add more trace data.
				term\trace_file_handle = OpenFile(TRM_default_trace_filename$)
				While Not Eof(term\trace_file_handle)
					dummy$ = ReadLine (term\trace_file_handle)
				Wend


Any help appreciated.

EDIT: I think I'd need to get the file length and perform a seek on the file using that length (in bytes).


boomboom(Posted 2008) [#2]
If you could use the ini format for your files then there are a large collection of tools in the cod archs to do this for you?


Bobysait(Posted 2008) [#3]
use SeekFile(Stream,Offset) to "jump" to the expected byte offset.
here, you'll be abble to insert data into the file.

for convinience, you'd better reserve the header to store the mains offsets of the file. Like this, anytime you need infos, you rippe the header, and go directly to offsets listed.


_33(Posted 2008) [#4]
#1 It is not an INI file, but a TXT file
#2 Since it is a TXT file, I can't just dump a 4 byte word in there

EDIT: Well...
Print FileSize("file.txt")
WaitKey()
End
Hah! So it looks like this:
				term\trace_file_handle = OpenFile(TRM_default_trace_filename$)
				SeekFile(term\trace_file_handle, FileSize(TRM_default_trace_filename$))
Don't bother, this should work.