How to find if a Template Exists before opening a chart

 

I am trying to establish if a template exists for a specific currency pair before trying to open a new chart from within my MT5 EA then applying the template


string FileLocation  = TerminalInfoString(TERMINAL_DATA_PATH)+"\\";
   FileLocation = FileLocation +"MQL5\\";            
   FileLocation = FileLocation +"Profiles\\";
   FileLocation = FileLocation +"Templates\\";
   FileLocation = FileLocation +"RP_AUDUSD.tpl";
   if ( FileIsExist(FileLocation) == true  ) Report_StringError("Both","250015 OAC Template File "+FileLocation+" Exists");


My Report_StringError traps the error code and prints to a file for testing.

The above code returns an error "error: 5002 Invalid file name" does not exist.

The template does exist.

Is this something that I should be able to 'check' in MT5 or have I misunderstood?

Any help appreciated

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
 
Peter Williams: I am trying to establish if a template exists for a specific currency
string FileLocation  = TerminalInfoString(TERMINAL_DATA_PATH)+"\\";
   FileLocation = FileLocation +"MQL5\\";            
   FileLocation = FileLocation +"Profiles\\";
   FileLocation = FileLocation +"Templates\\";
   FileLocation = FileLocation +"RP_AUDUSD.tpl";

You can't read outside the sandbox with normal code.

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.
          FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum (2017)

Can a file that exists outside of the MetaTrader folders be opened? - MQL4 programming forum #1-#3 (2020)
File Path for saving .csv files in MT5 - MQL5 programming forum (2019)
File Operations via WinAPI - MQL4 Articles (2008)