RickZeeland
Вот некоторые процедуры, которые я попробовал и проверил:
/// <summary>
/// Recursively copy directory (XCOPY style), except file to skip.
/// Existing files will be overwritten.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="skipFileName">File to skip.</param>
public static void CopyAll(string source, string target, string skipFileName)
{
var sourceDi = new DirectoryInfo(source);
var targetDi = new DirectoryInfo(target);
CopyAll(sourceDi, targetDi, skipFileName);
}
/// <summary>
/// Recursively copy directory (XCOPY style), except file to skip.
/// Existing files will be overwritten.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="skipFileName">File to skip.</param>
public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string skipFileName)
{
// Check if the target directory exists, if not, create it.
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
// Copy each file into it’s new directory, except files to skip.
foreach (var fileInfo in source.GetFiles())
{
if (fileInfo.Name != skipFileName)
{
Debug.Print(@"Copying {0}\{1}", target.FullName, fileInfo.Name);
fileInfo.CopyTo(Path.Combine(target.ToString(), fileInfo.Name), true);
}
}
// Copy each subdirectory using recursion.
foreach (var subDir in source.GetDirectories())
{
if (subDir.Name != target.Name)
{
var nextTargetSubDir = target.CreateSubdirectory(subDir.Name);
CopyAll(subDir, nextTargetSubDir, skipFileName);
}
}
}