怎样用程序实现一个文件的复制

解决方案 »

  1.   

    wchar_t cstrSrcDir[MAX_PATH] ;
        SHFILEOPSTRUCT aFileOpStruct;
     
        if( strSrcDir==_T(""))
        {
            return false;
        }        wmemset(cstrSrcDir,0, MAX_PATH); 
        wmemcpy(cstrSrcDir, strSrcDir, strSrcDir.GetLength());
        ZeroMemory(&aFileOpStruct, sizeof(SHFILEOPSTRUCT));
        aFileOpStruct.pFrom = cstrSrcDir;
        aFileOpStruct.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;
        aFileOpStruct.wFunc = FO_COPY;
        return ( SHFileOperation(&aFileOpStruct) == 0 );也可以直接用CopyFile();
      

  2.   

    用下面的函数
    BOOL CopyFile(
      LPCTSTR lpExistingFileName, // name of an existing file
      LPCTSTR lpNewFileName,      // name of new file
      BOOL bFailIfExists          // operation if file exists
    );