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" error. Below is my code.
could any one suggest on this?
string sourcedirectory = @"F:source";
string destinationdirectory = @"F:destination";
try
{
if (Directory.Exists(sourcedirectory))
{
if (Directory.Exists(destinationdirectory))
{
Directory.Move(sourcedirectory, destinationdirectory);
}
else
{
Directory.CreateDirectory(destinationdirectory);
Directory.Move(sourcedirectory, destinationdirectory);
}
}
}
catch (Exception ex)
{
log(ex.message);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…