Can't delete a simple file with FileDetele()

 

Hi,


I have been trying to do a very simple operation for 2 days without success...delete a simple file.


This is an EA and this is what I have at the moment:


 FileDelete(MYfileNameWithExtensionIncluded,"C:\\Users\\Username\\AppData\\Roaming\\MetaQuotes\\Terminal\\Common\\Files\\MyFolder\\");


So, I want to delete "MYfileName" from the folder "MyFolder", inside the "Files" folder in MetaTrader common folder. Simple hein? Not to me...


I have tried to use this example from documentation:

 //--- Common folder for all client terminals 
          string common_data_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH);


So, I tried this:

 //--- Common folder for all client terminals 
          string common_data_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH);

 FileDelete(MYfileNameWithExtensionIncluded,common_data_path);



//ALSO TRIED THIS...

 FileDelete(MYfileNameWithExtensionIncluded,common_data_path + "\\");


//ALSO TRIED THIS


 FileDelete(common_data_path + "\\" + MYfileNameWithExtensionIncluded);


I simply can't delete this file... And to get worse, there are no errors on the log file (experts tab).


Can anyone please tell me what am I doing wrong?


Thank you in advanced.

 

Did you try to read the documentation or to search ?

 FileDelete("MyFolder\\"+MYfileNameWithExtensionIncluded,FILE_COMMON);
Search - MQL5.community
Search - MQL5.community
  • www.mql5.com
Searching is based on morphology and is insensitive to case. All letters, no matter of their case, will be processed as lowercase. By default, our search engine shows pages, that...
 
Alain Verleyen:

Did you try to read the documentation or to search ?

Yes I did, as mentioned.

I just tried that code, but it's still not working. This is what I've tried:

 FileDelete("test\\USDCAD.dica",FILE_COMMON); 

See the location on the image attached.

This can't be that difficult..something is missing me..

Location of file to delete

 
Can you access the file for reading, writing etc. At least then you know the directory is correct...
 
cf23EA1l:

Yes I did, as mentioned.

I just tried that code, but it's still not working. This is what I've tried:

See the location on the image attached.

This can't be that difficult..something is missing me..


FileDelete

Deletes the specified file in a local folder of the client terminal.

bool  FileDelete(
   const string  file_name,     // File name to delete 
   int           common_flag=0  // Location of the file to delete
   );

Parameters

file_name

[in]  File name.

common_flag=0

[in] Flag determining the file location. If common_flag = FILE_COMMON, then the file is located in a shared folder for all client terminals \Terminal\Common\Files. Otherwise, the file is located in a local folder.

Return Value

In case of failure the function returns false.

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.

I don't know how you are reading the documentation which is very clear. You need to place your files in Common\Files\ not directly in Common.
Documentation on MQL5: Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
Documentation on MQL5: Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
CSV file (all its elements are converted to strings of the appropriate type, Unicode or ANSI, and separated by separator). Flag is used in FileOpen(). Shared access for reading from several programs. Flag is used in FileOpen(), but it does not replace the necessity to indicate FILE_WRITE and/or the FILE_READ flag when opening a file. Shared...
 
Alain Verleyen:
I don't know how you are reading the documentation which is very clear. You need to place your files in Common\Files\ not directly in Common.

I am back (I am using a timer and the market was closed so I could not test it during the weekend).

Finally.... I guess I got confused when I read the "Common" bit... I assumed it was the "Common" folder and not "Common\Files".

Thank you for pointing this out. I knew this could not be that difficult!

It's now fixed and working. 

Thank you very much to all.

Reason: