diff --git a/CompareFS/PathComparator.cs b/CompareFS/PathComparator.cs index 50607a7..52638c8 100644 --- a/CompareFS/PathComparator.cs +++ b/CompareFS/PathComparator.cs @@ -10,9 +10,13 @@ public class PathComparator { private IPathModificationListener Listener; + public List ExcludedFileExtensions { get; private set; } + public PathComparator(IPathModificationListener listener) { Listener = listener; + + ExcludedFileExtensions = new List(); } public void Compare(DirectoryInfo referenceDirectory, DirectoryInfo targetDirectory) @@ -40,14 +44,19 @@ private void CompareSubdirectories(DirectoryInfo referenceDirectory, DirectoryIn private void CompareFiles(DirectoryInfo referenceDirectory, DirectoryInfo targetDirectory) { - foreach (FileInfo fi in targetDirectory.EnumerateFiles().Where(f => !referenceDirectory.HasFile(f))) + foreach (FileInfo fi in EnumerateLeftFilesMissingRight(targetDirectory, referenceDirectory)) { Listener.OnModification(new FileModification(fi, ModificationType.Added)); } - foreach (FileInfo fi in referenceDirectory.EnumerateFiles().Where(f => !targetDirectory.HasFile(f))) + foreach (FileInfo fi in EnumerateLeftFilesMissingRight(referenceDirectory, targetDirectory)) { Listener.OnModification(new FileModification(fi, ModificationType.Removed)); } } + + private IEnumerable EnumerateLeftFilesMissingRight(DirectoryInfo leftFiles, DirectoryInfo rightFiles) + { + return leftFiles.EnumerateFiles().Where(f => !ExcludedFileExtensions.Contains(f.Extension)).Where(f => !rightFiles.HasFile(f)); + } } } diff --git a/ComparePathCLI/Program.cs b/ComparePathCLI/Program.cs index efaa31f..98b4942 100644 --- a/ComparePathCLI/Program.cs +++ b/ComparePathCLI/Program.cs @@ -11,14 +11,27 @@ class Program { static void Main(string[] args) { - if (args.Length < 2) + if (args.Length < 2 || args.Length % 2 != 0) { - Console.WriteLine("Usage: ComparePathCLI path1 path2"); + Console.WriteLine("Usage: ComparePathCLI (-i extension)* path1 path2"); return; } var comparator = new PathComparator(new PathModificationConsoleWriter()); - comparator.Compare(new DirectoryInfo(args[0]), new DirectoryInfo(args[1])); + + for (int i = 0; i < args.Length - 2; i += 2) + { + if (args[i] == "-i") + { + comparator.ExcludedFileExtensions.Add(args[i+1]); + } + else + { + Console.WriteLine("Skipping unknown option \"{0}\"", args[i]); + } + } + + comparator.Compare(new DirectoryInfo(args[args.Length - 2]), new DirectoryInfo(args[args.Length - 1])); } } }