Trouble with eof...
BlitzMax Forums/BlitzMax Beginners Area/Trouble with eof...
| ||
I'd like to append to a file. Currently, I have a loop that tests eof. When eof hits, I'm trying to Writeline some more data. It finds eof, prints a debug notification that it's writing to the file, but the file remains the same. What's going on here? Small example: Repeat Print "searching in file..." Local line:String = ReadLine(file) ' if line$ has what I want, I exit this loop ' if I never find the thing I want, I'll append it to the file: If Eof(file) Then Print "found eof, writing more..." WriteLine file, "yada" EndIf Forever |
| ||
...And how the heck do I make one of those nice, scrollable boxes in a post? |
| ||
are you opening the stream as writable? OpenStream:TStream( url:Object,readable=True,writeable=True ) |
| ||
Actually I had not written in those flags, so it was working with defaults. But even after I put them in, I get the same result. Thanks though. |
| ||
So, to absolutely simplify the question, I should ask "How do I write to the end of a file?" |
| ||
Local myfile:TStream = OpenStream("test.txt") While Not Eof(myfile) Print ReadLine(myfile) Wend SeekStream(myfile, StreamSize(myfile)) WriteLine(myfile, "yada") CloseStream(myfile) FlushMem |
| ||
Thank you Tonyg. I never thought of using seekstream. I can't make the proper changes in my code, so I'll start over with yours and build up from there. ps. How did you make that box? I want to know, damnit! |
| ||
Forum Codes: http://www.blitzbasic.com/faq/faq_entry.php?id=2 |
| ||
Ah, well that's very handy. Thank you. I suppose If I can't find it in a sticky, I won't find it. |
| ||
Isn't this a bug? You shouldn't need to seek to the end of the file as you're already there... Local myfile:TStream = OpenStream("test.txt") While Not Eof(myfile) Print ReadLine(myfile) Wend Print myfile.Pos() SeekStream(myfile, StreamSize(myfile)) Print myfile.Pos() WriteLine(myfile, "yada") CloseStream(myfile) FlushMem end...Or have I missed something? |
| ||
I would agree with you, but I don't know anything. |
| ||
EOF takes you to the end of the file. If you could add a newline command then you might be able to continue. I just didn't know how to do that so gave the way I knew. |