Clearing a csv-File

 

Hi,

I am using this functions:

https://www.mql5.com/en/articles/1540

How should I clear the text in my csv-File?

Should I delete it and create it new, or is there a better way?

 
sunshineh:

Hi,

I am using this functions:

https://www.mql5.com/en/articles/1540

How should I clear the text in my csv-File?

Should I delete it and create it new, or is there a better way?

Write without read ?
 

I tried it that way:

int ClearFile (string path) 
  { 
    int result;
    int handle=_lopen (path,OF_WRITE);
    result=_llseek (handle,0,0);
    result=_lwrite (handle," ",1); 
    result=_lclose (handle);              
    if(result<0)  
    {
        return(-1);
    }
    return(1);
  }  


But this does only overwrite the first letter.

Does it works, when I delete the file an create it.

What is, when another expert advisor want's to read the file just at this moment?

 
sunshineh:

I tried it that way:


But this does only overwrite the first letter.

Does it works, when I delete the file an create it.

What is, when another expert advisor want's to read the file just at this moment?

Of course it works if you delete it first then create a new one, though other EA will have error "file not exist" when trying to open it, so other EA will have to wait for awhile and retry again later.
 
Silly question, but how can I delete it??
 
sunshineh:
Silly question, but how can I delete it??

Silly answer : I dunno.

Sorry :( 

 
sunshineh:
Silly question, but how can I delete it??

How can you delete the file ?  FileDelete()  ?


The old trick to handling 2 applications or EAs looking at the same file was to write the file with a name of xxxx  and when the file is complete to rename it to yyyyy  rather than creating it with the correct name in the first place.  You can't rename using standard mql4 functions but maybe you can with a kernel32 call . . .  or similar.

 
RaptorUK:

How can you delete the file ?  FileDelete()  ?


The old trick to handling 2 applications or EAs looking at the same file was to write the file with a name of xxxx  and when the file is complete to rename it to yyyyy  rather than creating it with the correct name in the first place.  You can't rename using standard mql4 functions but maybe you can with a kernel32 call . . .  or similar.


Sunshineh, was using this article https://www.mql5.com/en/articles/1540 . The file may be created outside experts/file folder.

Sunshineh, I prefer to use what you have tried there, but I guess you have to write a lot of lines :( 

 
phi.nuts:


Sunshineh, was using this article https://www.mql5.com/en/articles/1540 . The file may be created outside experts/file folder.

Ah . . OK :-)