title: How to delete a file by extension in Python?
body: <p>I was messing around just trying to make a script that deletes items by ".zip" extension.</p>
  
  <pre><code>import sys
  import os
  from os import listdir
  
  test=os.listdir("/Users/ben/downloads/")
  
  for item in test:
      if item.endswith(".zip"):
          os.remove(item)
  </code></pre>
  
  <p>Whenever I run the script I get:</p>
  
  <pre><code>OSError: [Errno 2] No such file or directory: 'cities1000.zip'
  </code></pre>
  
  <p>cities1000.zip is obviously a file in my downloads folder.</p>
  
  <p>What did I do wrong here?  Is the issue that os.remove requires the full path to the file?  If this is the issue, than how can I do that in this current script without completely rewriting it.</p>