I am trying to move the directory from one location to another location on the same drive. I am getting \"Cannot create a file when that file already exists
As per MSDN,
This method throws an IOException if, for example, you try to move c:\mydir to c:\public, and c:\public already exists.
But, in your method, you are creating the destination directory before you move.
So, you need to change your method from
if (Directory.Exists(destinationdirectory))
{
Directory.Move(sourcedirectory, destinationdirectory);
}
else
{
Directory.CreateDirectory(destinationdirectory);
Directory.Move(sourcedirectory, destinationdirectory);
}
to
if (Directory.Exists(destinationdirectory))
{
//delete or rename
}
Directory.Move(sourcedirectory, destinationdirectory);