Reading values from file

 
   string FileName = "c://report.txt";
   int handle = FileOpen(FileName, FILE_TXT|FILE_READ);
   if(handle!=INVALID_HANDLE){
      string MyString = FileReadString(handle);
      FileClose(handle);
   }

Can anyone spot why this code does not work, I get an invalid handle, the file does exist.


Steve

 
scarr:

Can anyone spot why this code does not work, I get an invalid handle, the file does exist.


Steve

This file is not in the sandbox (MQL4/Files).
 
scarr:

Can anyone spot why this code does not work, I get an invalid handle, the file does exist.


Steve

You can not open a file from that folder

Check this : https://www.mql5.com/en/docs/files/fileopen (especially this part : "For security reasons, work with files is strictly controlled in the MQL language. Files with which file operations are conducted using MQL means, cannot be outside the file sandbox."

Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
File Functions / FileOpen - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks guys your fantastic :-)

 

I'm back, Wow MT4 is not easy :-( well not for me anyway :-)

OK can anyone give me the path where I can read a file, I have tried loads of ones I think are right but they don't work :-(


The most recent filepath/name is this


C:\\Users\\scarter\\AppData\\Roaming\\MetaQuotes\\Terminal\\AA248EFC925E5BFD04BE26DB77C272A4\\MQL4\\Files\\values.txt


Steve

 
scarr: can anyone give me the path where I can read a file,

C:\\Users\\scarter\\AppData\\Roaming\\MetaQuotes\\Terminal\\AA248EFC925E5BFD04BE26DB77C272A4\\MQL4\\Files\\values.txt

  1. Don't use double backslash, except in code. character constants
  2. Everything before "values.txt" is the sandbox. Just use "values.txt"
  3. In the tester the file goes in Tester\Files not MQL4\Files. #2 still applies.
  4. Don't double post!
 

I still can't get it to work, this is the line of code. I tried single backslash but that would not compile.


   string FileName = "C:\\Users\\scarter\\AppData\\Roaming\\MetaQuotes\\Terminal\\AA248EFC925E5BFD04BE26DB77C272A4\\MQL4\\Files\\report.txt";


Steve
 
scarr:

I still can't get it to work, this is the line of code. I tried single backslash but that would not compile.



Steve

Did you read what whroeder1 wrote?
Specifically, point 2. from his answer?


string FileName = "report.txt";
Reason: