Can't create a CSV file from terminal

 

I am not able, from Meta Editor, to open/create a CSV file to write in it.

The code made in this purpose doesn't return any error or warning, filehandle=1; LastError=0;

but still I don't see any CSV file being created afterward in the destination subfolder.

void OnDeinit(const int reason)
  {
//---
   
   //Print("passed=",passed);
   ArrayPrint(bullmatricearray);
   int filehandle = FileOpen("Experts/Files/bullmatricearray.csv",FILE_READ|FILE_WRITE|FILE_CSV,",");
   Print("filehandle=",filehandle);
   FileSeek(filehandle,0,SEEK_END);
   FileWrite(filehandle,"column1","column2","column3","column4","column5","column6","column7","column8","column9","column10");
   for(im=0 ; im<10 ; im++)
    {
   FileWrite(filehandle,bullmatricearray[im][0],bullmatricearray[im][1],bullmatricearray[im][2],bullmatricearray[im][3],bullmatricearray[im][4],bullmatricearray[im][5],bullmatricearray[im][6],bullmatricearray[im][7],bullmatricearray[im][8],bullmatricearray[im][9]);
    }
   FileClose(filehandle);
   Print("Error=",GetLastError());
  }

Do you see any code mistake, or the issue might be outside the terminal ?

 

You are applying the 'FileOpen' operation, but you are not checking the result of the operation. Check the result of the operation - there will be a description of your error (Your error is that you do not read the Documentation).

 

I have simplified and corrected your example

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Print(__FUNCTION__);
   ResetLastError();
   int filehandle=FileOpen("Experts\\Files\\bullmatricearray.csv",FILE_READ|FILE_WRITE|FILE_CSV,",");
   Print("filehandle=",filehandle);
   if(filehandle<0)
     {
      Print("Failed to open the file by the absolute path ");
      Print("Error code ",GetLastError());
     }
   FileSeek(filehandle,0,SEEK_END);
   FileWrite(filehandle,"column1");
   for(int i=0; i<10; i++)
     {
      FileWrite(filehandle,IntegerToString(i));
     }
   FileClose(filehandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  }
//+------------------------------------------------------------------+

You should look for your file in the "sandbox"

("you will find the sandbox after you read the Documentation")

Files:
Test.mq5  4 kb
 
Vladimir Karputov #:

I have simplified and corrected your example

You should look for your file in the "sandbox"

("you will find the sandbox after you read the Documentation")

After reading some documentation I understood the "sandbox" was defining the "folders scope", the only ones which can be accessed from the terminal.

I tested your code and the result was the same.

The issue was then me not searching at the right place. I am testing the code with the tester and the documentation says " The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing)" , so I was searching there :

C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\ FB9A56D617EDDDFE29EE54EBEFFEXXXX\...tester   but is was there :

C:\Users\user\AppData\Roaming\MetaQuotes\Tester\FB9A56D617EDDDFE29EE54EBEFFEXXXX\testing_agent_directory\MQL5\Files\Experts\Files

Thanks for your help

Reason: