Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Intersecting Partial Matches
    primarykey
    data
    text
    <p>Good Afternoon all, I'm trying to run a comparison of the contents of 2 folders and I have it working after-a-fashion but I'm curious whether there's a better way. Here's what I have:</p> <pre><code> static void Main(string[] args) { reportDiffs("C:\\similar\\a", "C:\\similar\\b"); Console.WriteLine("--\nPress any key to quit"); Console.ReadKey(); } public static void reportDiffs(string sourcePath1, string sourcePath2) { string[] paths1 = Directory.GetFiles(sourcePath1); string[] paths2 = Directory.GetFiles(sourcePath2); string[] fileNames1 = getFileNames(paths1, sourcePath1); string[] fileNames2 = getFileNames(paths2, sourcePath2); IEnumerable&lt;string&gt; notIn2 = fileNames1.Except(fileNames2); IEnumerable&lt;string&gt; notIn1 = fileNames2.Except(fileNames1); IEnumerable&lt;string&gt; inBoth = fileNames1.Intersect(fileNames2); printOut("Files not in folder1: ", sourcePath2, notIn1); printOut("Files not in folder2: ", sourcePath1, notIn2); printOut("Files found in both: ", "", inBoth); } private static string[] getFileNames(string[] currentFiles, string currentPath) { string[] currentNames = new string[currentFiles.Length]; int i; for (i = 0; i &lt; currentNames.Length; i++) { currentNames[i] = currentFiles[i].Substring(currentPath.Length); } return currentNames; } private static void printOut(string headline, string currentPath, IEnumerable&lt;string&gt; fileNames) { Console.WriteLine(headline); foreach (var n in fileNames) { Console.WriteLine(currentPath + n); } Console.WriteLine("--"); } </code></pre> <p>It feels like I'm missing a trick and that there's an existing array method, like Intersect, that I could have passed paths1 &amp; paths2 to rather than doing the fileNames1 &amp; 2 step but, for the life of me, I couldn't find anything like it in the framework.</p> <p>Cheers, Sam</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload