title: If file exists, overwrite it?
body: <p>I'm creating an application to backup files and I need to check if the file exist and if so overwrite it.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>private void Copy(string sourceDir, string targetDir)
  {
      Directory.CreateDirectory(targetDir);
  
      foreach (var file in Directory.GetFiles(sourceDir))
      {
          File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)));
          logWindow.AppendText("\nCopying file" + file + "Complete");
      }
  
      foreach (var directory in Directory.GetDirectories(sourceDir))
      {    
          Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
          logWindow.AppendText("\n" + directory);
      }
  </code></pre>