C#文件。未找到复制目录
我正在尝试用C#复制C#文件。未找到复制目录,c#,.net,C#,.net,我正在尝试用C#复制文件 我得到一个目录NotFoundException。但是,我验证了目录是否存在 我的代码: try { log.Info("Copying file from '" + srcFile + "' to '" + destFile + "'"); log.Info("Source File: '" + srcFile + "' exists: " + File.Exists(srcFile)); File.Copy(srcFile, destFil
文件
我得到一个目录NotFoundException
。但是,我验证了目录是否存在
我的代码:
try
{
log.Info("Copying file from '" + srcFile + "' to '" + destFile + "'");
log.Info("Source File: '" + srcFile + "' exists: " + File.Exists(srcFile));
File.Copy(srcFile, destFile, true);
log.Info("Copied file to '" + destFile + "' success");
}
catch (System.Exception ex)
{
log.Error("Send Logs: Log file copy error", ex);
}
运行代码的结果:
2017-08-30 09:20:25,933 [1] INFO [ArbitrationForums.AFClient.AFSystemTray.MainForm] Copying file from 'C:\Users\ptenn\AppData\Roaming\ArbitrationForums\logs\AFDashboard.log' to 'C:\Users\ptenn\AppData\Roaming\ArbitrationForums\AFClient\DataSpool\AFDashboard.log'
2017-08-30 09:20:25,933 [1] INFO [ArbitrationForums.AFClient.AFSystemTray.MainForm] Source File: 'C:\Users\ptenn\AppData\Roaming\ArbitrationForums\logs\AFDashboard.log' exists: True
2017-08-30 09:20:25,934 [1] ERROR [ArbitrationForums.AFClient.AFSystemTray.MainForm] Send Logs: Log file copy error
System.IO.DirectoryNotFoundException: Could not find a part of the path
'C:\Users\ptenn\AppData\Roaming\ArbitrationForums\logs\AFDashboard.log'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String
destFileName, Boolean overwrite, Boolean checkHost)
at ArbitrationForums.AFClient.AFSystemTray.MainForm.sendLogs()
我应该有权限,因为我是以用户身份登录的,我将访问他们的AppData\Roaming
文件夹
到底有没有人有什么想法或建议
非常感谢 在这一点上,我支持替马溴铵。我建议您的目标目录不存在“C:\Users\ptenn\AppData\Roaming\仲裁论坛\AFClient\dataSpool\“清除该文件。Exists()
检查。这真的帮不了你,你查过电话了吗?sourceFileName或destFileName中指定的路径无效(例如,它位于未映射的驱动器上)。您不太可能验证所有以管理员身份运行该程序的用户的目录“C:\Users\ptenn\AppData\Roaming\仲裁论坛\logs”是否存在,并查看这是否有任何不同。ID是否检查目标目录是否确实存在?