Download MetaTrader 5

File operation

To add comments, please log in or register
och
485
och  
Hi all,
Just trying to copy/move some files from tester/AgentXXX/MQL5/Files to some other directory, let say TERMINAL_PATH. I tried FileMove, FileCopy and even ShellExecuteW, nothing works, any help welcome!
Regards,
Olivier
Alexey Da
Moderator
6648
Alexey Da  
och:
Hi all,
Just trying to copy/move some files from tester/AgentXXX/MQL5/Files to some other directory, let say TERMINAL_PATH. I tried FileMove, FileCopy and even ShellExecuteW, nothing works, any help welcome!
Regards,
Olivier
Do you receive any error?
och
485
och  
alexvd:
Do you receive any error?

Hi,

Not really, Error 0 :

 

handle = ShellExecuteW(0,0,"copy","C:\test.ini" "c:\mt5\mql5\files\test.ini\","",1);

    Sleep(1200);

    if(handle>32) Print(__FUNCTION__, " : Ini file moved sucessfully");                                       

    else { Print(__FUNCTION__, " : Error while trying to move the optiization ini file: ",GetLastError()); return(true);}

I tried als FileCopy and FileMove MQL function but none of them seems to work.

 

I would like to move a file from TERMINAL_DATA_PATH to another directory whereever I want (I mean not necessary Metatrader directory.

Any idea? 

Regards,

Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
Standard Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions - Documentation on MQL5
Alexey Da
Moderator
6648
Alexey Da  

Try to do something like this

It should  works fine.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#import "kernel32.dll"
int GetLastError(void);
int CopyFileW(
              string &lpExistingFileName,
              string &lpNewFileName,
              int bFailIfExists
              );
#import
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnStart()
  {
   string src="d:\\netstat.txt";
   string dest="e:\\test.txt";
   int res=kernel32::CopyFileW(src,dest,1);
   Print("Result is ",res,", last error is ",kernel32::GetLastError());
//---
   return(0);
  }
//+------------------------------------------------------------------+

Do not forget that you should write "\\" if you want to add \ character into the string. 

Serge
457
Serge  
alexvd:

Try to do something like this

It should  works fine.

Do not forget that you should write "\\" if you want to add \ character into the string. 

Hi. Why do I get error 'GetLastError' - ambiguous call to overloaded function with the same parameters sapi.mq5 80 41 and how can I fix it? Code attached.

Files:
sapi.mq5 4 kb
Alexey Da
Moderator
6648
Alexey Da  
Graff:
Hi. Why do I get error 'GetLastError' - ambiguous call to overloaded function with the same parameters sapi.mq5 80 41 and how can I fix it? Code attached.

You have to add scope resolution operation as you did on line 67.

The reason is that the system function GetLastError() and the function which you have imported from dll are placed in global scope and they have the same name and argument list. So you have to specify which of them you want to call.

Serge
457
Serge  
alexvd:

You have to add scope resolution operation as you did on line 67.

The reason is that the system function GetLastError() and the function which you have imported from dll are placed in global scope and they have the same name and argument list. So you have to specify which of them you want to call.

Thanks, works fine.
To add comments, please log in or register