我正在用 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 文件)
谢谢!