Download MetaTrader 5

File : Open, read line by line, use what has been read, close

To add comments, please log in or register
Publish programs in Code Base. Improve your rating!
Icham Aidibe
10043
Icham Aidibe 2014.11.27 09:25 

Hi ! Here's the code & what it returns. Would love to be helped on that function !

   ResetLastError();
   string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
   string subfolder="Settings";
   string filename = Symbol + ".set";
   StringToLower(filename);
int filehandle=FileOpen(subfolder+"\\"+filename,FILE_TXT|FILE_READ);
   if(filehandle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is available for reading",filename);
      //--- additional variables
      //int    str_size;
      string str;
      //--- read data from the file
      while(!FileIsEnding(filehandle))
        {

         //--- read the string
         str=FileReadString(filehandle,-1);
         //--- print the string
         PrintFormat(str);
        }
      //--- close the file
      FileClose(filehandle);
      PrintFormat("Data is read, %s file is closed",filename);
     }
   else
      PrintFormat("Failed to open %s file, Error code = %d",filename,GetLastError());


I can see that in the expert tab :

Data is read, ger30.set file is closed <- end
2014.11.27 08:59:14 Ger30Dec14 0 <- is that the file read line by lines ? 
File path: C:\Users\blouf\AppData\Roaming\MetaQuotes\Terminal\9DC46CFC75DA31CE79A53E3CEEF53781\Files\ <- where's that coming from ? that's not the folder I use
ger30.set file is available for reading <- seems to be correctly checked
Icham Aidibe
10043
Icham Aidibe 2014.11.27 10:01  
blouf:

Hi ! Here's the code & what it returns. Would love to be helped on that function !


I can see that in the expert tab :

It seems that for security reason there's a limitation using file to the file sandbox, I've changed the path, but still no change even if the path to the file is correct :

Using now this code :

   string fullpath = terminal_data_path + "\\" + subfolder + "\\" + filename;
   int filehandle=FileOpen(fullpath,FILE_TXT|FILE_READ);
   printf("Path to the file : %s",fullpath);
Failed to open ger30.set file, Error code = 5002
Path to the file : C:\Users\blouf\AppData\Roaming\MetaQuotes\Terminal\9DC46CFC75DA31CE79A53E3CEEF53781\Files\ger30.set
Icham Aidibe
10043
Icham Aidibe 2014.11.27 17:57  
Solved. No extra path, just the terminal path set & the filename.
Alain Verleyen
Moderator
30734
Alain Verleyen 2014.11.27 20:13  
blouf:
Solved. No extra path, just the terminal path set & the filename.
To add comments, please log in or register