使用c#将文件夹从一个驱动器移动到另一个驱动器

Here is my source file and destination file";

Source :  E:\\Test\Test_Content\\ABC12
Destination: F:\\Test\GetContent

我想将文件夹ABC12从E驱动器移到GetContent文件夹内的目标路径,但是
ABC12包含不同的子文件夹. ABC12文件夹应与子文件夹一起完全移动到目标文件夹.请帮我.

我收到以下错误消息:我收到了这样的错误消息:“源路径和目标路径必须具有相同的根.移动将无法跨卷进行.”

 string sfolder="Path of the folder to move which is in project directory in E drive";
 string path = "~/UContent" + "/" + sfolder;
                string extractfiles = Server.MapPath("UContent"+"/");
               System.IO.Directory.Move(extractfiles+"/"+sfolder,@"F:/GetContent/");

解决方法:

你需要这个:

static public void CopyFolder(string sourceFolder, string destFolder )
{
    if (!Directory.Exists( destFolder ))
        Directory.CreateDirectory( destFolder );
    string[] files = Directory.GetFiles( sourceFolder );
    foreach (string file in files)
    {
        string name = Path.GetFileName( file );
        string dest = Path.Combine( destFolder, name );
        File.Copy( file, dest );
    }
    string[] folders = Directory.GetDirectories( sourceFolder );
    foreach (string folder in folders)
    {
       string name = Path.GetFileName( folder );
       string dest = Path.Combine( destFolder, name );
        CopyFolder( folder, dest );
    }
}
上一篇:CodeGo.net>如何将复杂的对象集合传递给控制器​​在MVC


下一篇:剑道DatePicker最大值和最小值不限制文本输入