I am using the following method to copy the contents of a directory to a different directory.
public void DirCopy(string SourcePath, string DestinationPath)
{
if (Directory.Exists(DestinationPath))
{
System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(DestinationPath);
foreach (FileInfo file in downloadedMessageInfo.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
{
dir.Delete(true);
}
}
//=================================================================================
string[] directories = System.IO.Directory.GetDirectories(SourcePath, "*.*", SearchOption.AllDirectories);
Parallel.ForEach(directories, dirPath =>
{
Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
});
string[] files = System.IO.Directory.GetFiles(SourcePath, "*.*", SearchOption.AllDirectories);
Parallel.ForEach(files, newPath =>
{
File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);
});
}
My only issue is that there is quite a bit of data in the source path and the program becomes non responsive while the copying is taking place.
I am wondering what my options are for copying data. I did some research and someone had recommended to use a buffer.
I have not really seen any solution that I understand particularly well so any help/resources that are clear and concise would be great.
Thanks for any help!