Cố gắng sử dụng này:
public static void RobustMove(string sourceDirectory, string destDirectory)
{
//move if directories are on the same volume
if (Path.GetPathRoot(source) == Path.GetPathRoot(destination))
{
Directory.Move(source, destination);
}
else
{
CopyDirectoryRecursive(source, destination);
Directory.Delete(source, true);
}
}
Bạn sẽ tìm thấy chức năng CopyDirectoryRecursive here:
này nên được làm việc cho đến khi bạn sử dụng spanned volume hoặc biểu tượng liên kết đến một đĩa vật lý.
Để mạnh mẽ hơn nữa, bạn có thể cải thiện chức năng này để sử dụng Di chuyển cho đến khi System.IO. Ngoại lệ được ném và sau đó chuyển sang sao chép và xóa.