Unable to open csv file

 

Hi there,

I receive this error:

5004

ERR_FILE_CANNOT_OPEN

Cannot open file


It happens when trying to open a csv file to read it.

input string fileName="calendar_statement.csv";
input string directoryName="Files";
datetime newsItemDateTime;
int size;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   getNewsTime();
  }
//+------------------------------------------------------------------+
void getNewsTime()
  {  
   ResetLastError();
   int fileHandle=FileOpen(directoryName+"\\"+fileName,FILE_READ|FILE_CSV);
   if(fileHandle!=INVALID_HANDLE)
     {
      Print("Test ran");
      PrintFormat("%s file is open for reading",fileName);
      //--- first, read the number of signals
      size=(int)FileReadNumber(fileHandle);
      //--- read data from the file
      for(int i=0;i<size;i++)
        {
         FileReadDatetime(fileHandle);
        }
      //--- close the file
      FileClose(fileHandle);
     }
   else
     {
      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError());
     }
  }// end getNewsTime

The full path is C:\MetaTrader - Pepperstone\MQL4\Include\Files\calendar_statement.csv.

Thanks!

 

I tried to attach the csv but didn't work.  This is an extract:

Date,Event,Impact,Previous,Consensus,Actual,Currency
"2014, January 01, 01:00",(United States) Consumer Confidence,High,70.4,76,77.5,USD
"2014, January 02, 18:13",(Spain) Markit Manufacturing PMI,High,48.6,49.9,50.8,EUR
"2014, January 02, 18:43",(Italy) Markit Manufacturing PMI,High,51.4,51.8,53.3,EUR
"2014, January 02, 18:48",(France) Markit Manufacturing PMI,High,48.4,47.1,47,EUR
"2014, January 02, 18:53",(Germany) Markit Manufacturing PMI,High,52.7,54.2,54.3,EUR
"2014, January 02, 18:58",(Greece) Markit Manufacturing PMI,High,49.2,,49.6,EUR
 

brad:

The full path is C:\MetaTrader - Pepperstone\MQL4\Include\Files\calendar_statement.csv.


FileOpen

Note

For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox.

The file is opened in the folder of the client terminal in the subfolder MQL4\files (or Tester\Files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 4 client terminals.

 
brad: The full path is C:\MetaTrader - Pepperstone\MQL4\Include\Files\calendar_statement.csv.
  1. Put it where it belongs. Dated 17.02.2014 12:45: Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles
  2. directoryName+"\\"+fileName
    Take out the "directoryName\"  as it's already in the FileOpen
Reason: