title: File Copy failing to create files with same name
body: <p>I am copying files from one location to another. I encountered an issue where sometimes a file with the same name would try to save and it would break the program. So I added the logic below to add a number to the filename before copying it:</p>
  <pre><code>                int counter = 0;
                  try
                  {
                      File.Copy(FileToCopy, FileToSave);
  
                  }
                  catch (Exception)
                  {
                      string CurrentFileName = FileToSave.Split('\\', '\\')[4];
                      string CurretFilePrefix = CurrentFileName.Split('.')[0];
                      string CurrentFileSuffix = CurrentFileName.Split('.')[1];
                      string UpdatedFileName = CurretFilePrefix + &quot;_&quot; + counter + &quot;.&quot; + CurrentFileSuffix;
                      File.Copy(FileToCopy, UpdatedFileName);
                      counter++;
                  }
  </code></pre>
  <p>However, this is now causing a crash saying the file already exists:</p>
  <p><a href="https://i.stack.imgur.com/s5utP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s5utP.png" alt="enter image description here" /></a></p>
  <p>When I check the file does not exist:</p>
  <p><a href="https://i.stack.imgur.com/7y3f6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7y3f6.png" alt="enter image description here" /></a></p>
  <p>Why am I getting this exception? How do I save copies of these files?</p>