1

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 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

You can use File.Move with all files of the directory. This method works across volumes (see remarks).
Sorry, I wasn't as specific as I hoped, I meant with Directory.Move.
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).
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.
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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.