public static void CopyDirectory(string source, string target, bool forceCreateTarget = true, bool recursive = true, ILog log = null) { log.Info("Directorio que se copiará de: " + source + " a " + target); if (recursive) { foreach (string dir in Directory.EnumerateDirectories(source)) { log.Info(dir); string onlyDir = dir.Substring(source.Length + 1); SUtilIO.CopyDirectory(dir, Path.Combine(target, onlyDir), forceCreateTarget, recursive, log); } } List <string> lFileNames = SUtilIO.ReadFileNames(source); SUtilIO.CopyFiles(source, lFileNames, target, forceCreateTarget, log); }
private static void CopyFiles(string source, List <string> lFileNames, string target, bool forceCreateTarget, ILog log) { if (forceCreateTarget) { SUtilIO.CreateDirectory(target, log); } foreach (var FicheroOrigen in lFileNames) { string rutaOrigen = Path.Combine(source, FicheroOrigen); string rutaDestino = Path.Combine(target, FicheroOrigen); try { SUtilIO.CopyFile(rutaOrigen, rutaDestino, log); } catch (IOException ioex) { if (log != null) { log.Error(ioex.Message); } throw; } } }