【问题标题】:Directory.Move not working properly for UNC pathsDirectory.Move 不适用于 UNC 路径
【发布时间】:2017-07-28 10:46:58
【问题描述】:

我想将目录移动到新位置,然后我使用Directory.Move API,但它不适用于 UNC 路径,例如

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

它会抛出异常

[System.IO.IOException] = {"源和目标路径必须有 同根。移动无法跨卷工作。"}

我没有找到任何措辞告诉这个 API 不适用于来自MSDN 的 UNC 路径。那么哪个 API 适用于 UNC 路径?

【问题讨论】:

    标签: c# .net io


    【解决方案1】:

    如果它们位于不同的卷上,您将无法移动。 MOVE 是一种文件系统操作,无需复制即可更改其所在位置。要跨不同卷移动,您必须复制它,然后删除旧卷。

    它与 UNC 无关。从 C:\something 移动到 D:\something 会以同样的方式和出于同样的原因出错。

    【讨论】:

    • "\\Server1\Path1" 和 "\\Server1\Path2" 应该在同一个卷,但是不同的目录,对吧?
    • @CarlosLiu Path1 & Path2 是 Server1 上的共享名称。 "\\Server\Share\Path1" 到 "\\Server\Share\Path2" 是同一共享的不同文件夹。
    • @BlackFrog 感谢您的解释。 Directory.Move(@"\\Server\Share\Path1", @"\\Server\Share\Path2") 将起作用
    猜你喜欢
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 2016-12-14
    • 1970-01-01
    • 2013-09-26
    • 2012-08-29
    • 2011-07-12
    相关资源
    最近更新 更多