如何跨卷移动目录,sun目录及其文件(例如,在同一服务器上从F:\到D:\) [英] How to move directories, sun-directories and their files accross volumes (F:\ to D:\ on the same server as an example)

查看:74
本文介绍了如何跨卷移动目录,sun目录及其文件(例如,在同一服务器上从F:\到D:\)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有有效的代码将指定目录及其子文件夹+文件从同一卷上的一个卷移动到另一个卷吗?需要一些行之有效且有效的方法.预先谢谢您.

Anyone have working code to move specified directory and its sub-folders + files from one volume to another on the same server? Need something that works right and is effecient. Thank you in advance.

推荐答案

这并不难.你为什么不写呢?
您所要做的就是拥有指定的源根目录和目标根目录.
然后遍历源根目录中的所有目录,并将每个目录中的所有文件和目录创建/复制到目标根目录.

您可以查看此线程,它为您提供了两个潜在的解决方案:
This isn''t hard. Why don''t you write it.
All you have to do is have a specified source root and a destination root.
Then iterate through all the directories in the source root and create/copy all the files and directories in each to the destination root.

You can check out this thread which has a couple of potential solutions for you: Clicky[^]


没有不错"的方式-目录.移动不能跨卷进行,因为它只是(有效地)重写了位置,而不是移动任何数据.
递归File.Copy操作是一种解决方案,但存在作弊"问题.
添加对Microsoft.VisualBasic的引用,那么它将起作用:

There isn''t a "nice" way - Directory.Move can''t work across volumes since it just (effectively) re-writes the locations instead of moving any data.
Recursive File.Copy operations are one solution, but there is a "cheat".
Add a reference to Microsoft.VisualBasic, then this will work:

new Microsoft.VisualBasic.Devices.Computer().FileSystem.CopyDirectory(sourceDir, outputDir);


令人讨厌-但有效.然后,您可以在完成后删除源.


Nasty - but effective. You can then delete the source when completed.


这篇关于如何跨卷移动目录,sun目录及其文件(例如,在同一服务器上从F:\到D:\)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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