已知一个文件或文件夹,怎么样复制到一个指定的目录里,如是文件夹则要将文件夹及其包含的所有的文件都复制进去。可以用CFileFind类实现吗?我不知道CFileFind类有哪些函数。

解决方案 »

  1.   

    用SHFileOperation  复制
    来实现就可以了
      

  2.   

    用CFileFind的话,就要遍历你的文件夹
    然后判断是目录还是文件,依次拷贝过去就可以了。
    要用到CFileFile类的FindFile,FindNextFile,IsDirectory,IsDots,GetFilePath,GetFileName
      

  3.   

    system("cmd.exe xcopy/e c:\\11\\*.* c:\\22");
      

  4.   

    或者SHFILEOPSTRUCT fo;
    memset(&fo, 0, sizeof(fo));
    fo.wFunc = FO_COPY;
    fo.pFrom = "c:\\11\*.*\0"
    fo.pTo = "c:\\22\\\0"fo.fFlags = FOF_SIMPLEPROGRESS;
    SHFileOperation(&fo);
      

  5.   

    SHFILEOPSTRUCT  Op; 
       
      char FromBuf[]="E:\temp{post.content}"; 
      char ToBuf[]="\SINTEKSERVER\个人文档\陈 伟{post.content}";; 
       
      Op.hwnd = NULL; 
      Op.wFunc = FO_COPY; 
      Op.pFrom = FromBuf; 
      Op.pTo = ToBuf; 
      Op.fFlags = FOF_NOCONFIRMATION | FOF_RENAMEONCOLLISION ; 
      Op.fAnyOperationsAborted = FALSE; 
      Op.hNameMappings = NULL; 
      Op.lpszProgressTitle = NULL; 
       
      if(SHFileOperation(&Op) == 0) 
      MessageBox("复制完毕","提示",MB_OK|MB_ICONINFORMATION); 
      

  6.   

    char FromBuf[]="E:\temp{post.content}"; 
      char ToBuf[]="\SINTEKSERVER\个人文档\陈 伟{post.content}";; 
    改成这样
    char FromBuf[]="E:\\temp"; 
      char ToBuf[]="\\SINTEKSERVER\\个人文档\\陈 伟";
      

  7.   

    system("xcopy/y e:\\test d:\\test\\");
    这样也可以复制文件或者文件夹
      

  8.   

    http://community.csdn.net/Expert/topic/4989/4989935.xml?temp=.5589563
    看看,呵呵,已经解决过了
      

  9.   

    Visual Studio 2005 的写法有些不同,我测试过,如下:         wchar_t * szSourcePath = _T("J:\\testFrom\\*.*\0");
    wchar_t * szDestinationPath = _T("J:\\testTo\\\0"); SHFILEOPSTRUCT FileOP; //SHFILEOPSTRUCT声明
    ZeroMemory(&FileOP, sizeof(FileOP));  //SHFILEOPSTRUCT成员赋值
    FileOP.hwnd = AfxGetApp()->m_pMainWnd->m_hWnd;
    FileOP.fFlags = FOF_SILENT;
    FileOP.wFunc = FO_COPY;
    FileOP.pFrom = szSourcePath;
    FileOP.pTo = szDestinationPath;
    FileOP.fAnyOperationsAborted = FALSE; //
    FileOP.hNameMappings = NULL;
    FileOP.lpszProgressTitle = NULL;
    //SHFILEOPSTRUCT成员赋值结束 int msg = SHFileOperation(&FileOP);//执行复制操作 if(msg==0)
      AfxMessageBox(_T("复制完成"));    else
    AfxMessageBox(_T("复制失败!!!"));