5002 | ERR_FILE_WRONG_FILENAME | Wrong file name |
Kiloromeo #:
Yes, I have looked this up and found it in the documentation.
Yes, I have looked this up and found it in the documentation.
The file name is not wrong.
That is why I decised to post.
Please provide a csv file.
Also
Please don't post randomly in any section. Your question is not related to the section you posted.
MQL4 and MetaTrader 4, has it's own section on the forum.
I will move your topic to the correct section later, please don't create another topic.
You should not append the full path in front of the filename.
Read the FileOpen documentation and check the example on that page.
Pay attention to the comments:
//| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- incorrect file opening method string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH); string filename=terminal_data_path+"\\MQL4\\Files\\"+"fractals.csv"; int filehandle=FileOpen(filename,FILE_WRITE|FILE_CSV); if(filehandle<0) { Print("Failed to open the file by the absolute path "); Print("Error code ",GetLastError()); } //--- correct way of working in the "file sandbox" ResetLastError(); filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV); if(filehandle!=INVALID_HANDLE) { FileWrite(filehandle,TimeCurrent(),Symbol(), EnumToString(ENUM_TIMEFRAMES(_Period))); FileClose(filehandle); Print("FileOpen OK"); } else Print("Operation FileOpen failed, error ",GetLastError()); //--- another example with the creation of an enclosed directory in MQL4\Files\ string subfolder="Research"; filehandle=FileOpen(subfolder+"\\fractals.txt",FILE_WRITE|FILE_CSV); if(filehandle!=INVALID_HANDLE) { FileWrite(filehandle,TimeCurrent(),Symbol(), EnumToString(ENUM_TIMEFRAMES(_Period))); FileClose(filehandle); Print("The file most be created in the folder "+terminal_data_path+"\\"+subfolder); } else Print("File open failed, error ",GetLastError()); }
![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
I have read the documentation and read all the related topics in the forum, but still cant find out what the problem is.
This is the path of the file:
C:\Users\danie\AppData\Roaming\MetaQuotes\Terminal\2C68BEE3A904BDCEE3EEF5A5A77EC162\MQL4\Files\test.csv
(This is the real path and also this is printed at Print(filename);
This is the content of the csv: (I even tryed it with an empty file.)
2021.02.01,00:00,1.21301,1.21364,1.20562,1.20594,63743,1.2130572,1.1665786,1.1952606,-0.0075899999999999,-0.007117,0.039361,0.00802,1.198349999999996
And this the code snippet where it fails:
The encoding of the file is UTF-8.
How can I troubleshoot, why it cant open the file?
Thank you