private static IEnumerable <CompareFile> IterateFolderComparison(string currentDir, string originalDir) { if (!Directory.Exists(currentDir)) { throw new Exception("currentDir is missing"); } if (!Directory.Exists(originalDir)) { throw new Exception("originalDir is missing"); } foreach (var file in Directory.GetFiles(currentDir, "*.js")) { var file2 = Path.Combine(originalDir, Path.GetFileName(file)); yield return(CompareFile.compare(file, file2)); } foreach (var subDir in new DirectoryInfo(currentDir).GetDirectories()) { foreach (var itm in IterateFolderComparison(subDir.FullName, originalDir + "\\" + subDir.Name)) { yield return(itm); } } }
public static CompareFile compare(string currentFile, string originalFile) { var itm = new CompareFile() { fileOriginal = originalFile, fileCurrent = currentFile }; if (!File.Exists(originalFile) || !File.Exists(currentFile)) { itm.status = ECompareFileStatus.missing; return(itm); } var originalLines = File.ReadAllLines(originalFile); var currentLines = File.ReadAllLines(currentFile); if (originalLines.Length != currentLines.Length) { itm.status = ECompareFileStatus.lineCount; return(itm); } for (var i = 1; i < currentLines.Length; i++) { if (originalLines[i] != currentLines[i]) { itm.status = ECompareFileStatus.lineDiff; itm.diff = new CompareFileDiff() { lineNumber = i + 1, lineContentCurrent = currentLines[i], lineContentOriginal = originalLines[i] }; return(itm); } } return(itm); }