如果失败,我可以保证MoveFile()不会丢失文件吗?

时间:2017-10-24 13:00:38

标签: c++ winapi

给出名为:

的CRITICAL文件
C:\Lvl1\test.file

我想转移到:

C:\Lvl1\Lvl2\test.file

使用:: MoveFile()函数,如果函数调用失败,我可以依赖MoveFile()来丢失文件数据吗?

执行此操作的代码可能类似于:

int main()
{
   bool bMoveFileFailed = false;

   // Please just accept that a "CalcCRC32()" exists and returns the file CRC32!
   uint crcOriginal = CalcCRC32("C:\\Lvl1\\test.file");
   if( FALSE == ::MoveFile("C:\\Lvl1\\test.file", "C:\\Lvl1\\Lvl2\\test.file") )
   {
      bMoveFileFailed = false;
   }
   std::cout << "MoveFile() " << (bMoveFileFailed ? "FAILED" : "SUCCEEDED") << std::endl;

   uint crcNew = CalcCRC32(bMoveFileFailed ? "C:\\Lvl1\\test.file" : "C:\\Lvl1\\Lvl2\\test.file");

   if ( crcNew == crcOriginal )
   {
      std::cout << "The File Integrity was maintained!" << std::endl;
   }
   else
   {
      std::cout << "The file was corrupted or lost!" << std::endl;
   }

   return 0;
}

0 个答案:

没有答案