File Streams - Appending to File
Blitz3D Forums/Blitz3D Programming/File Streams - Appending to File
| ||
I have a simple Logging function for a project, but I can't seem to get it to work correctly. Currently, the code just seems to overwrite a single line each time. I am not sure if it's related to the closing and re-opening. (Incidentally, what diffeerence(s) are there between OpenFile and WriteFile? ) However, I don't like to leave any files Open, especially as my program may involve other read/writes to other files elsewhere. Function Debug(sDebugFunction$="APPLICATION RUN",sDebugResult$="LOG START") If (DebugOn()) DebugFile=WriteFile(fLOGFILE$) SeekFile(DebugFile,FileSize(fLOGFILE$)) sLine$=CurrentDate$()+" | "+CurrentTime$()+" | "+sDebugFunction$+" | "+sDebugResult$ WriteLine(DebugFile,sLine$) CloseFile DebugFile EndIf Return End Function Any help would be really appreciated. |
| ||
Maybe try doing ReadLine to see if there is anything on that line first and loop it till it gets to an empty spot? |
| ||
Use OpenFile(), As far as im aware WriteFile() zeros the file ready for writing. You might want to use WriteFile() first to create a file. OpenFile() requires that the file exists. |
| ||
May offer some help: http://www.blitzbasic.com/Community/posts.php?topic=27896 |
| ||
Yes, you need to check to see if the log file exists, if it does use OpenFile, else use WriteFile. |
| ||
Oh the file definitely exists. OpenFile worked fine. Thanks for the info. I shoulda tried that before posting, really ;) |
| ||
file = OpenFile(path$) SeekFile file, FileSize(path$)The file is now opened for reading and writing and the file position is at the end of the file. |