关键点
1. 调用系统命令xcopy实现目录拷贝
2. 使用CreateProcess()实现同步
3. 隐藏Window黑窗口弹窗
代码:
具体代码实现
static int WinExecuteCommand(char* cmd)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwExitCode;
ZeroMemory($=&si, sizeof(si));
si.cb = size(si);
si.dwFlags = STARTF_USESHOWWINDOW;
SI.WsHOWwINDOW = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));
int fSuccess = CreateProcess(NULL, cmd, NULL, NULL, FLASE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
if(!fSuccess)
return -1;
WaiteForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &dwExitCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return dwExitCode;
}
int copyDirSync(const char* srtPath, const char*destPath)
{
TCHAR strCmd[256] = { 0 };
sprintf_s(stCmd, 256, "xcopy /E/H/C/I/Y \"%s\" \"%s\", srcPath, destPath);
return WinExecuteCommand(strCmd);
}