title: Python - Deleting the last few characters of specific files in a directory
body: <p>I'm trying to delete the last several characters of multiple files in a specific directory using the <code>rename</code> function. The code I have written using suggestions on this site looks like it should work, but it returns the error message:</p>
  
  <blockquote>
    <p>FileNotFoundError: [WinError 2] The system cannot find the file specified: 'test1.txt' -> 'test'</p>
  </blockquote>
  
  <p>And here is my code:</p>
  
  <pre><code>import os
  
  list = os.listdir("C:\\Users\\Jonathan\\Desktop")
  
  for file in list:
      if file.startswith("test"):
          os.rename(file, file[0:4])
  </code></pre>
  
  <p>My code shows that for all files beginning with the word "test", delete all characters after it. As I said, to me it looks like it should work, but I am new at Python, and I don't even understand what the error message means.</p>