Is possible re-write data in files?

 

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?

 
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.
 
Ok. But how do I do it in binary file?
 
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.

Reason: