I'm trying to cut a folder. I've tried directoy.move(string source,string dest) & directoryinfo.moveto(dest) but in both case an exception was thrown "Source and destination path must have identical roots. Move will not work across volume".
1 Answer
You cannot move files and folders across different volumes with Directory.Move. You have to create the directory at the destination, recursively copy the files across then, on success, delete the files at the source or, as Tim suggested in the comments below, recursively create the directory structure then move the files across with File.Move.
7 Comments
Tim Schmelter
You can use
File.Move with all files of the directory. This method works across volumes (see remarks).James Hunt
Sorry, I wasn't as specific as I hoped, I meant with
Directory.Move.Tim Schmelter
Now you've lost me. OP has tried
Directory.Move which does not work across volumns (as you've stated correctly) but you don't need to copy from a to b, then delete the old files. You can use File.Move instead which does both and works across volumns (as opposed to Directory.Move).James Hunt
My answer said that you CAN'T use
Directory.Move due to the fact it doesn't work across volumes, so I suggested using copy/paste instead. I assumed your first comment was to do with the fact I just said Move instead of Directory.Move instead of providing a more efficient way of moving the individual files.Tim Schmelter
We're talking past each other ;) I don't know if it's more efficient, but it's shorter and maybe more readable. However, it was just a suggestion for a small improvement.
|