我正在使用C#编写一个WPF应用程序,需要移动一些文件。问题是,我非常需要知道这些文件是否成功移动到目标目录。为了解决这个问题,我编写了一个检查程序来确保在移动后文件能够成功到达目标目录。但有时候我会在文件移动完成之前就执行检查程序,这是一个麻烦的问题。
System.IO.File.Move(file.FullName, endLocationWithFile);
System.IO.FileInfo[] filesInDirectory = endLocation.GetFiles();
foreach (System.IO.FileInfo temp in filesInDirectory)
{
if (temp.Name == shortFileName)
{
return true;
}
}
// The file we sent over has not gotten to the correct directory....something went wrong!
throw new IOException("File did not reach destination");
}
catch (Exception e)
{
//Something went wrong, return a fail;
logger.writeErrorLog(e);
return false;
}
有人能告诉我如何确保文件实际上已到达目的地吗?-我将要移动的文件可能非常大 - (长达2小时的全高清mp4文件)
谢谢!
Move
来自行管理移动呢?这样你就能确切地了解正在发生的事情。 - spender