Help: Copy Folders anywhere win32 api Access violation error

 

Hi


i am trying to write some code to allow me to copy files from my mql profile area into anywhere like say local pc or pc on local network.

I have tried some code with diffrent results.



 //this does nothing but returns success
    static bool mfs_CopyFolder(string in_srcPath, string in_tgtPath)
    {
        static uint lc_showNormal = 1;
   
        string lc_params = "/c copy " + in_srcPath + " " + in_tgtPath;
        int result = ShellExecuteW(0, "open", "cmd.exe", lc_params, NULL, lc_showNormal);
        bool lc_bRes = !(result <= 32);
  }

//this g
enerates access violation runtime error
static bool mfs_CopyFolder2(string in_srcPath, string in_tgtPath)
    {


        string lc_params = "/c copy /Y " + in_srcPath + " " + in_tgtPath;
        int result = ShellExecuteA(0, "open", "cmd", lc_params, 0, 0);
        //int result = ShellExecuteW(0, "open", "cmd", lc_params, NULL, 0);        
        bool lc_bRes = !(result <= 32);
}


Any tips much appreciated. Since i want to copy outside of mt5, i cannot use mql file api.

Cheers

 
JamesWoods: Any tips much appreciated. Since i want to copy outside of mt5, i cannot use mql file api.
Stop trying to kludge around the problem. Fix the problem; make a junction at «DataFolder»\MQL4\Files\other and use the regular.
          Can a file that exists outside of the MetaTrader folders be opened? - MQL4 programming forum #1-#3 (2020)
 

Hi

let use kernel32.dll

#import "kernel32.dll"
   bool CopyFileW(string existingFile, string newFile, bool overwrite);
#import
 
Trinh Dat #:

Hi

use let use kernel32.dll

Hi


thanks for the feedback , i just tried your suggestion 


 static bool mfs_CopyFolder3(string in_srcPath, string in_tgtPath)
    {
        bool res = CopyFileW(in_srcPath, in_tgtPath, false);

        M_LOG_ERROR(
            M_C_StrgMgrSvc_T,
            (!res),
            N_LGR::E_LG_LVL::e_info,
            ("filecopy for " + typename(T_StrgClient) + "WinErr= " + IntegerToString(RtlGetLastWin32Error()) )
            );

        return res;
    }


I was getting windows error code 5 = access denied. The test was on random folders copy from c drive to d drive on my pc.

I am trying to copy entire folders from anywhere to anywhere, any tips much appreciated.  This is code i want to use to update my VPS to save me some maintenance headache.


Cheers

 
#include <fxsaber\MultiTester\MTTester.mqh> // https://www.mql5.com/ru/code/26132

void OnStart()
{
  const string FileNameIn = MQLInfoString(MQL_PROGRAM_PATH);
  const string FileNameOut = "C:\\Example.ex5";
  
  MTTESTER::FileCopy(FileNameIn, FileNameOut);
}
 
fxsaber #:

Hi

your function uses CopyFileW, and am getting the same win error 5, access violation.

All am trying to do is test folder copy from one location on pc to another. I am not trying to copy files, i am trying to copy folders


cheers

 
fxsaber #:

Just a bit more info in case it helps.

the folders to and from for my test are 


 string lc_to = "D:\\Development\\Projects\\MQL5\\TestData\\ProfileTest";
  string lc_from2 = "D:\\Development\\Projects\\MQL5\\TestData\\temp\\*.*";

  static bool mfs_CopyFolder4(string in_fromPath, string in_toPath)
    {
          bool res = MTTESTER::FileCopy(in_fromPath, in_toPath);

          M_LOG_ERROR(
            M_C_StrgMgrSvc_T,
            (!res),
            N_LGR::E_LG_LVL::e_info,
            ("filecopy for " + typename(T_StrgClient) + "WinErr= " + IntegerToString(RtlGetLastWin32Error()) )
            );

        return res;
    }

 I get windows error code 123 for invalid name, other times i get error code 5 for access denied.


Any help much appreciated.

If i have to i will write console app to move files around, but for now am trying to move files around from inside the EA for my vps update.

cheers



Reason: