private static TimeSpan Test()
{
var w = new Stopwatch();
w.Start();
CopyDir(new DirectoryInfo("e://test"), new DirectoryInfo("e://test1"));
w.Stop();
return w.Elapsed;
}
private static void CopyDir(DirectoryInfo s, DirectoryInfo d)
{
if (!d.Exists)
d.Create();
Parallel.Invoke(
() =>
{
Parallel.ForEach(s.GetFiles(), f =>
{
var t = new FileInfo(Path.Combine(d.FullName, f.Name));
f.CopyTo(t.FullName);
Total++;
});
},
() =>
{
Parallel.ForEach(s.GetDirectories(), subs =>
{
var subd = new DirectoryInfo(Path.Combine(d.FullName, subs.Name));
CopyDir(subs, subd);
});
});
}