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 DirectoryInfo
instance and use the MoveTo(destDirName)
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 should Use Copy Function followed by a remove. As Move only works in the same drive.
Directory.Move
has a condition that states that :
IO Exception will be thrown if an attempt was made to move a directory to a different volume.
Another option is, to add a reference to the Microsoft.VisualBasic
namespace and use the MoveDirectory
method, which can move across volumes.
Microsoft.VisualBasic.FileIO.FileSystem.MoveDirectory(sourceDirName, destDirName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With