简体   繁体   English

等到所有文件都复制完?

[英]Wait until all the files are copied?

I am trying to find a way to wait until xcopy cmd finished copying files from a disk.我试图找到一种方法来等待 xcopy cmd 完成从磁盘复制文件。 I tried 2 ways.我尝试了 2 种方法。 First way is basically waiting for hprocess from the created process.第一种方法基本上是从创建的进程中等待hprocess

But this waitForSingleObject never resolves.但是这个waitForSingleObject永远不会解决。

void copyFileWait(){

  STARTinfP777.cb = sizeof(STARTinfP777);
  char allCmd[MAX_PATH] = "C:\\Windows\\System32\\cmd.exe /k copy /y \""; // = drive letter; xcopy working fine
  printf("%s\n", allCmd);

  DWORD safsdkasf = 0;
  if(CreateProcess(NULL, allCmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &STARTinfP777, &procInf7777) == 0){

    printf("%d\n", GetLastError());
    MessageBox(0, "Hata", "Dikkat!", MB_OK);
    exit(0);
  }
  WaitForSingleObject( procInf7777.hProcess, INFINITE );
  CloseHandle( procInf7777.hProcess );
  CloseHandle( procInf7777.hThread );

}

In this function, i check the exitcode of the process after ran with GetExitCodeProcess() and also set a timer on the code.在这个函数中,我在使用GetExitCodeProcess()运行后检查进程的退出代码,并在代码上设置一个计时器。 But it always equals to 259 i dont notice any change after even the files are completely written.但它总是等于259 ,即使文件完全写入后我也没有注意到任何变化。

 void copyFileWait();
void gggPaths();
DWORD WINAPI GetDirsSEVENthreadFunc ();

//void cpyToPES(char fromWhereToCopy[MAX_PATH]);

char *WndCmpath = "C:\\Windows\\System32\\cmd.exe ";

HANDLE fileCopierHandle;
int Nprocess = 0;

STARTUPINFO STARTinfP777 = {0};
PROCESS_INFORMATION procInf7777 = {0};
DWORD exitcode;

int main(){

    gggPaths();

    //copyFileWait();

    DWORD threadCPYFilesID;
    fileCopierHandle=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)GetDirsSEVENthreadFunc,(LPVOID)10,0,&threadCPYFilesID); //updating 0 olana kadar bekler
    WaitForSingleObject(fileCopierHandle,INFINITE);

    printf("done.");
    return 0;
}

void copyFileWait(){

  STARTinfP777.cb = sizeof(STARTinfP777);
    char allCmd[MAX_PATH] = "C:\\Windows\\System32\\cmd.exe /k copy /y \""; // = drive letter; //xcopy files  bla bla works fine
    printf("%s\n", allCmd);



  DWORD safsdkasf = 0;
  if(exitcode != 259){
      if(CreateProcess(NULL, allCmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &STARTinfP777, &procInf7777) == 0){

        printf("%d\n", GetLastError());
        MessageBox(0, "Hata", "Dikkat!", MB_OK);
        exit(0);
      }
  }

  BOOL result = GetExitCodeProcess(procInf7777.hProcess, &exitcode);
  if(!result){
      memset( &STARTinfP777, '\0', sizeof STARTinfP777 );
      memset( &procInf7777, '\0', sizeof procInf7777 );
      printf("damn..\n");
      printf("%d\n", GetLastError());
  }else{

  }
  printf("exitcode => %d", exitcode);
  //if() exıtcode TASK_COMPLETE forexample... kill timer etc.
}


DWORD WINAPI GetDirsSEVENthreadFunc (){
  HWND tempHW;
  SetTimer(tempHW, 0, 5500,(TIMERPROC) &copyFileWait);
  MSG msg;
  while(GetMessage(&msg, NULL, 0, 0)){
   TranslateMessage(&msg);
   DispatchMessage(&msg);
 }
}

What would be a way to accomplish this task ?完成这项任务的方法是什么?

I tried CopyFile() But it didnt find the path when i linked other volume letters, or external devices.我试过CopyFile()但是当我链接其他卷字母或外部设备时它没有找到路径。 Which I am working on.我正在处理的。

/k切换到/c解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM