Reputation: 6073
I am trying to do a File.Copy
in C#.
I get a DirectoryNotFoundException
. However, I verified the directory exists.
My code:
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);
}
Results of running the code:
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()
I should have permissions since I am logged on as the user that I am going to their AppData\Roaming
Folder.
At wits end, does anyone have any ideas or suggestions?
Thanks very much!
Upvotes: 1
Views: 1649
Reputation: 2210
I'm with Timamonium on this one. I'd suggest that your destination directory does not exist "C:\Users\ptenn\AppData\Roaming\ArbitrationForums\AFClient\DataSpool\"
Upvotes: 2