Here is my source file and destination file:
Source:
E:\Test\Test_Content\ABC12
Destination:
F:\Test\GetContent
I want to move folder ABC12 from E drive to destination path within GetContent folder. However, ABC12 contains different sub folder, and ABC12 folder should be completely move to destination folder along with subfolder.
I am getting the following error:
"Source and destination path must have identical roots. Move will not work across volumes."
Here is my code:
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/");
You need this:
static public void CopyFolder(string sourceFolder, string 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 );
}
}
Move function worked only if the source and destination is in the same drive
You can use Copy followed by a Remove in that case
Refer the below link for copying a directory to another drive
Copy a directory to a different drive
Then use
Directory.Delete(source_path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With