title: Better Way to Copy Move Rename File, Visual Basic (VS 2012 V11)
body: <p>I want to copy, rename, and move a file to a new location. According to <a href="http://msdn.microsoft.com/en-us/library/36xbexyf(v=vs.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/36xbexyf(v=vs.90).aspx</a> the following code should do so:</p>
  
  <blockquote>
    <p>This example copies the file Test.txt to the directory TestFiles2 and
    renames it NewFile.txt.</p>
  </blockquote>
  
  <pre><code>My.Computer.FileSystem.CopyFile _
  ("C:\UserFiles\TestFiles\test.txt", _
  "C:\UserFiles\TestFiles2", "NewFile.txt", FileIO.UICancelOption.DoNothing)
  </code></pre>
  
  <p>However, when I type this code it only sees the "NewFile.txt" parameter as the Boolean parameter that handles overwrites. I believe this is a mistake on the websites part.</p>
  
  <p>If I can't use "My.Computer.FileSystem.CopyFile" (unless I am doing something wrong) to copy rename and move a file, is there a better way then this:</p>
  
  <pre><code>' Rename the file to be copied the name you want it to be in the new location
  My.Computer.FileSystem.RenameFile("C:\OriginalFile.txt", "OriginalFileTemporaryName.txt")
  
  ' Copy the file to the new location and overwrite if it exists there
  My.Computer.FileSystem.CopyFile ("C:\OriginalFileTemporaryName.txt", "C:\UserFiles\TestFiles2", True)
  
  ' Rename the original file back to it's original name
  My.Computer.FileSystem.RenameFile("C:\OriginalFileTemporaryName.txt", "OriginalFile.txt")
  </code></pre>
  
  <p>The problem I have with the above is that I might end up renaming the original file a temporary name that already exists in the original files location. I want to avoid that. I also do not want to rename the copied file in the destination folder because I do not see an option to force an overwrite for "My.Computer.FileSystem.RenameFile"</p>
  
  <p>Is this even a half decent solution? 
  <strong>Is there not a better way to do this?</strong></p>