Here exceptions occur when,
* The specified path/searchoption is not a valid one.
* You are trying to access an unmapped network location.
* You do not have the persmission.
I have taken a sample from the microsoft website. Just insert the following code into your function.
string sourceDirectory = @"C:\current";
string archiveDirectory = @"C:\archive";
try
{
var txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt", SearchOption.AllDirectories);
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourceDirectory.Length + 1);
Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName));
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Now debug your application and see what happens. If it runs correctly, then just re-check your old argument
directory and give a valid path; then you are good to go.
In case if you catch an error in these blocks, have a debug point inside the catch block and see what type of exception is thrown.
<br />
Path Invalid -> ArgumentException / ArgumentNullException / DirectoryNotFoundException / IOException / PathTooLongException
Access Denied -> SecurityException / UnauthorizedAccessException
SearchOption Invalid -> ArgumentOutOfRangeException
Please check and correct your inputs based on the types exception thrown. I hope you can modify your code based on these information and make it work seamlessly.
Please get back if you need any more help with the issue.