Download MetaTrader 5

Is possible re-write data in files?

To add comments, please log in or register
Pavel Soukup
560
Pavel Soukup 2014.02.18 15:30 

Hi guys,

how re-write data in csv (or bin) files?

My code:

int start()
  {
   int handle;
   handle=FileOpen(WindowHandle(Symbol(),Period())+".csv",FILE_CSV|FILE_READ|FILE_WRITE);
   if(handle<1)
   {
     Alert("Error open file...", GetLastError());
     return(false);
   }
   string str="#001";
   FileWrite(handle, str);
   FileWrite(handle, "ORDER_ID");
   FileWrite(handle, 125125125);
   FileWrite(handle, 225225225);
   FileSeek(handle,16,SEEK_SET);
   Alert(FileReadNumber(handle));
   return(0);
  }

And I want re-write example: 125125125 to 5555555 or add text "_CLOSED", change ORDER_ID to ORDER_ID_CLOSED?

Ex Ovo Omnia
3194
Ex Ovo Omnia 2014.02.18 15:37  
I do not think the CSV implementation can overwrite in a safe way. Either use binary file write or limit the expectations to appending to the end of the CSV.
Pavel Soukup
560
Pavel Soukup 2014.02.18 15:42  
Ok. But how do I do it in binary file?
Ex Ovo Omnia
3194
Ex Ovo Omnia 2014.02.18 18:41  
endy5:
Ok. But how do I do it in binary file?


With binary file, you can navigate using FileSeek to the point you want the replacing starts, and replace by FileWriteString

Snaž se trochu, nemůžu psát všechno.

To add comments, please log in or register