See section File Functions:
For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.
There are two directories (with subdirectories) in which working files can be located:
- terminal_path\MQL5\FILES\ (in the terminal menu select to view "File" - "Open the data directory");
- the common folder for all the terminals installed on a computer - usually located in the directory C:\Documents and Settings\All Users\Application Data\MetaQuotes\Terminal\Common\.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The following code always returns -1.
#include <Files\FileTxt.mqh>
CFileTxt oF ;
string sFileName = "c:\tmp\FXReport.txt" ;
void OnStart()
{
//---
if ( oF.IsExist ( sFileName ) )
{
Print ( "File Exits" ) ;
oF.Open ( sFileName, FILE_REWRITE ) ;
}
else
{
Print ( "RetCode: ", oF.Open ( sFileName, FILE_WRITE | FILE_CSV) ) ;
}
oF.WriteString ( "This,is,a,test" ) ;
oF.WriteString ( "1This,2is,3a,4test" ) ;
oF.Save (oF.Handle ( ) ) ;
oF.Close ( ) ;
}