Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory.Move not working properly for UNC paths

Tags:

c#

.net

io

I want to move a directory to a new location, then I use the Directory.Move API, but it does not work for the UNC path, e.g.

Directory.Move(@"\\Server1\Path1", @"\\Server1\Path2");

It will throw below exception

[System.IO.IOException] = {"Source and destination path must have identical roots. Move will not work across volumes."}

And I did not find any wordings tell this API not work for UNC path from MSDN. So which API works for the UNC path?

like image 845
Carlos Liu Avatar asked Oct 18 '22 16:10

Carlos Liu


1 Answers

You can't MOVE if they are on different volumes. MOVE is a file system operation that changes where it lives without copying it. To move across different volumes, you would have to copy it, then delete the old one.

It has nothing to do with UNC. Moving from C:\something to D:\something would error the same way and for the same reason.

like image 128
Tim Avatar answered Oct 20 '22 10:10

Tim