How can I copy all of the contents in one directory to another with out looping over each file?
See Question&Answers more detail:osHow can I copy all of the contents in one directory to another with out looping over each file?
See Question&Answers more detail:osYou can't. Neither Directory
nor DirectoryInfo
provide a Copy
method. You need to implement this yourself.
void Copy(string sourceDir, string targetDir)
{
Directory.CreateDirectory(targetDir);
foreach(var file in Directory.GetFiles(sourceDir))
File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)));
foreach(var directory in Directory.GetDirectories(sourceDir))
Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
}
Please read the comments to be aware of some problems with this simplistic approach.