title: How do I compare one collection of files to another in c#?
body: <p>I am just learning C# (have been fiddling with it for about 2 days now) and I've decided that, for leaning purposes, I will rebuild an old app I made in VB6 for syncing files (generally across a network).</p>
  
  <p>When I wrote the code in VB 6, it worked approximately like this:</p>
  
  <ol>
  <li>Create a <code>Scripting.FileSystemObject</code></li>
  <li>Create directory objects for the source and destination</li>
  <li>Create file listing objects for the source and destination</li>
  <li>Iterate through the source object, and check to see if it exists in the destination
  
  <ul>
  <li>if not, create it</li>
  <li>if so, check to see if the source version is newer/larger, and if so, overwrite the other</li>
  </ul></li>
  </ol>
  
  <p>So far, this is what I have:</p>
  
  <pre><code>private bool syncFiles(string sourcePath, string destPath) {
      DirectoryInfo source = new DirectoryInfo(sourcePath);
      DirectoryInfo dest = new DirectoryInfo(destPath);
  
      if (!source.Exists) {
          LogLine("Source Folder Not Found!");
          return false;
      }
  
      if (!dest.Exists) {
          LogLine("Destination Folder Not Found!");
          return false;
      }
  
      FileInfo[] sourceFiles = source.GetFiles();
      FileInfo[] destFiles = dest.GetFiles();
  
      foreach (FileInfo file in sourceFiles) {
          // check exists on file
      }
  
      if (optRecursive.Checked) {
          foreach (DirectoryInfo subDir in source.GetDirectories()) {
              // create-if-not-exists destination subdirectory
              syncFiles(sourcePath + subDir.Name, destPath + subDir.Name);
          }
      }
      return true;
  }
  </code></pre>
  
  <p>I have read examples that seem to advocate using the FileInfo or DirectoryInfo objects to do checks with the "Exists" property, but I am specifically looking for a way to search an existing collection/list of files, and not live checks to the file system for each file, since I will be doing so across the network and constantly going back to a multi-thousand-file directory is slow slow slow.</p>
  
  <p>Thanks in Advance.</p>