FileOpen

 
I took the following sample from www.metaquotes.net site. I am not able to open a file using this sample. The FileOpen function returns -1. Does anyone know what could be the problem?

Code:

int h1;
h1 = FileOpen("mydata.csv", FILE_CSV, ";");
if(h1<0)
{
Comment("Unable to open file my_data.csv",h1);
return(false);
}

Output: Unable to open file my_data.csv -1
(Of course mydata.csv is not created).
 
I'm not sure FileOpen will create a file... the dictionary doesn't indicate if it will create a new file if it can't find an existing file... and there is no FileNew() function....

""Opens file for input and/or output. Returns a file handle for the opened file. A return value less than 1 indicates an error.
Note: Files can be opened only from MetaTrader_dir\experts\files directory and it's subdirectories. ""

Try creating a "mydata.csv" file with a text editor and see if it opens it...

d
 
I tried different things including your suggestion. It doesn't work. I also tried to qualify the filename with the pathname. Still no luck.
 
Just add FILE_WRITE mode.

int start()
  {
   int hnd;
//----
   hnd=FileOpen("mydata.csv", FILE_CSV|FILE_WRITE,";");
   if(hnd<0)
     {
      Comment("Unable to open file my_data.csv");
      return(0);
     }
   FileWrite(hnd, Close[0], Open[0], High[0], Low[0]);
   FileClose(hnd);
//----
   return(0);
  }
 
Renat,

Did you really try it? I cann't still get the file created or opened. The FileOpen() function returns -1. To avoid mistakes, I cut & pasted your code as is. I have no luck.

Thanks.
 
It's working (100% tested). Check /experts/files folder.
Build 134.
 
in our dictionary sample written
===
handle = FileOpen("my_data.dat",FILE_CSV|FILE_READ,";");
===
insert back FILE_READ mode please.
and we well check once more default mode