title: Rename files in directory with first 8 characters and keep file extensions (Python)
body: <p>I have a directory with 1000 files, all of the files start with an 8 digit unique identifier, for example <code>12345678-foo.txt</code>.</p>
  
  <p>I'd rather not manually edit all 1000 files and have tried to write some Python code to do this for me:</p>
  
  <pre><code>for filename in os.listdir("C:/Users/me/Data/test"):
      extension = filename[-4:]
      os.rename(filename, filename[:8] + extension)
  </code></pre>
  
  <p><strong>This works on the first 6 or so files then I get the following error:</strong></p>
  
  <pre><code>WindowsError: [Error 183] Cannot create a file when that file already exists
  </code></pre>
  
  <p>None of the files have duplicate names since the first 8 characters are unique.</p>