failed to delete file and clear folder

 

Hi, I tried to delete a file and clear a cache from strategy tester and here's how I do it.

void CStrategy::InitDeleteFile(string CurrentSymbol, TRADE_DIRECTION TradeDirection) {

   string tradeDirection;
   if(InpTradeDirection == LONG_ONLY)
      tradeDirection = "Long Trade";
   if(InpTradeDirection == SHORT_ONLY)
      tradeDirection = "Short Trade";

   string BacktestFileName  = StrategyName +" "+ CurrentSymbol +" "+ tradeDirection +" Report.xml";
   string ForwardFileName   = StrategyName +" "+ CurrentSymbol +" "+ tradeDirection +" Report.forward.xml";

   string LocationPath = "C:\\Users\\ezral\\AppData\\Roaming\\MetaQuotes\\Terminal\\C71DA05AFD17F05D0A3C50314A211092\\MQL5\\Files\\Reports\\"+StrategyCategory+"\\"+StrategyName+"\\"+EnumToString(InpTradeTimeframe)+"\\";

   if(!FileDelete(LocationPath + BacktestFileName))
      Print("===== ERROR - failed to delete backtest report with error code ", GetLastError(), " =====");
   else
      Print("===== SUCCESS - deleting backtest report successfully =====");
   if(!FileDelete(LocationPath + ForwardFileName))
      Print("===== ERROR = failed to delete forward test report with error code ", GetLastError(), " =====");
   else
      Print("===== SUCCESS - deleting forward test report successfully =====");
};

//+------------------------------------------------------------------+
// Clear previous cache ----------------------------------------------------------------------------------------------+ //
void CStrategy::InitClearCache() {
   string CacheLocation = "C:\\Users\\ezral\\AppData\\Roaming\\MetaQuotes\\Terminal\\C71DA05AFD17F05D0A3C50314A211092\\Tester\\cache\\";
   if(!FolderClean(CacheLocation))
      Print("===== ERROR - failed to clear folder ", CacheLocation, " with error code ", GetLastError(), " =====");
   else
      Print("===== SUCCESS - clearing cache successfully =====");
};

and here's the print statement from the journal

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   ===== ERROR - failed to clear folder C:\Users\ezral\AppData\Roaming\MetaQuotes\Terminal\C71DA05AFD17F05D0A3C50314A211092\Tester\cache\ with error code 5002 =====

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   Location Path: \MQL5\Files\Reports\10 mean reversion\ATRl\PERIOD_M15\

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   backtest: \MQL5\Files\Reports\10 mean reversion\ATR\PERIOD_M15\ATR AUDCAD Long Trade Report.xml

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   Forward test: \MQL5\Files\Reports\10 mean reversion\ATR\PERIOD_M15\ATR AUDCAD Long Trade Report.forward.xml

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   ===== ERROR - failed to delete backtest report with error code 5002 =====

2024.01.13 14:03:12.187 Core 1 2022.10.06 00:00:00   ===== ERROR = failed to delete forward test report with error code 5002 =====
Both location for the reports file and cache folder is correct but it returns with error 5002. I looked at the Runtime error documentation for the error desc but the file name is already correct.

ERR_WRONG_FILENAME

5002

Invalid file name


Anyone knows how to fix this?

 

File operations are carried out in a sandbox. You can't use direct file paths. File paths are relative to the "MQL5\Files" path.

Note

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.

Deletes the specified file from a local folder of the client terminal (MQL5\Files or MQL5\Tester\Files in case of testing). If common_flag = FILE_COMMON, then the function removes the file from the shared folder for all client terminals \Terminal\Common\Files.