How can I update a CSV file without overwriting it?

 

Hello guys,

can someone tell me how to update a file without overwriting it? I made a small script which saves the current time to the file TEST.CSV. This script overwrites the file before but I want it to add the current time to the existing file so when I execute the script 5 times I want to see 5 different times. I think I have to open and read the file before and write the time at the end of the file but I don't know how to do it. Can someone help me with this?

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
   int filehandle=FileOpen("test.csv", FILE_WRITE|FILE_CSV); 
   if (filehandle!=INVALID_HANDLE) {
      FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_SECONDS));
   }
   FileClose(filehandle);
}
 
FileOpen(..., FILE_READ|FILE_WRITE|FILE_CSV);
FileSeek(..., SEEK_END);
 
Ivan Titov #:

Exactly what I needed. Thank you very much!

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
   int filehandle=FileOpen("test.csv",FILE_READ|FILE_WRITE|FILE_CSV); 
   if (filehandle!=INVALID_HANDLE) {
      FileSeek(filehandle,0,SEEK_END);
      FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_SECONDS));
   }
   FileClose(filehandle);
}