“移动将不会在卷上工作” - 为什么又如何克服? [英] "Move will not work across volumes" - Why? And how to overcome?

查看:151
本文介绍了“移动将不会在卷上工作” - 为什么又如何克服?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在源文件和目标文件位于不同的分区中时, File.Move(sourceFileName,destFileName)正常工作,但目录.Move(sourceDirName,destDirName)不要?它引发

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:源和目标路径必须有
相同的根。 。

System.IO.IOException: "Source and destination path must have identical roots. Move will not work across volumes."

我甚至尝试创建一个 DirectoryInfo 实例,并使用 MoveTo(destDirName)方法,但没有成功。

I even tried to create a DirectoryInfo instance and use the MoveTo(destDirName) method but without success.

我错过了什么?我真的需要自己实现移动功能吗? (我想要移动的目录是非常大的btw)。

Am I missing something? Do I really have to implement a "move" functionality myself? (the directory I want to move is very large btw).

推荐答案

你也可以p / invoke SHFileOperation 这是Windows资源管理器用来移动目录的功能。它将执行真正的移动或递归 - 然后删除,酌情。

You can also p/invoke SHFileOperation which is the same function Windows Explorer uses to move directories around. It will either perform a true move or recursive-copy-then-delete, as appropriate.

它也可以显示与浏览器相同的进度UI,只需设置一个标志。

It can also show the same progress UI as explorer, just by setting a flag.

这篇关于“移动将不会在卷上工作” - 为什么又如何克服?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆