first timer first timer - 7 months ago 44
C# Question

"Move will not work across volumes" - Why? And how to overcome?

Why is it that

File.Move(sourceFileName, destFileName)
works fine when the source file and destination files are in different partitions, but
Directory.Move(sourceDirName, destDirName)
don't? It throws

System.IO.IOException: "Source and destination path must have
identical roots. Move will not work across volumes."

I even tried to create a
instance and use the
method but without success.

Am I missing something? Do I really have to implement a "move" functionality myself? (the directory I want to move is very large btw).


You can also p/invoke SHFileOperation which is the same function Windows Explorer uses to move directories around. It will either perform a true move or recursive-copy-then-delete, as appropriate.

It can also show the same progress UI as explorer, just by setting a flag.