private static int AddSourceOnlyFiles(FolderDiffBase folderDiff, ProgressReporter progressReporter, int reportCount) { // Add source only files to target ProgressReporter.Logger.WriteLine("Copying " + folderDiff.SourceOnlyFiles.Length + " new files"); int consoleTh = folderDiff.SourceOnlyFiles.Length / reportCount; int k = 0; int errorCount = 0; Parallel.For(0, folderDiff.SourceOnlyFiles.Length, new ParallelOptions() { MaxDegreeOfParallelism = Program.MaxDegreeOfParallelism }, i => { string sourcePath = Path.Combine(folderDiff.SourcePath, folderDiff.SourceOnlyFiles[i]); string targetPath = Path.Combine(folderDiff.TargetPath, folderDiff.SourceOnlyFiles[i]); // read https://stackoverflow.com/questions/265953/how-can-you-easily-check-if-access-is-denied-for-a-file-in-net try { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Copy(sourcePath, targetPath); } catch (Exception e) { Interlocked.Increment(ref errorCount); ProgressReporter.Logger.WriteLine("\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\nERROR : " + e.ToString() + "\r\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\r\n"); } progressReporter.AddNewFileProgress(i); int progress = Interlocked.Increment(ref k); progressReporter.WriteDetailedNewFileReport(sourcePath, targetPath, i, LogLevel.File); if (consoleTh == 0 || progress % consoleTh == 0) { progressReporter.WriteReport(LogLevel.Console); } }); progressReporter.WriteReport(LogLevel.Console | LogLevel.File); return(errorCount); }