title: Error 32: The process cannot access the file
body: <p>I am trying to delete an image if it throws an IOError when trying to open it with PIL, but for some reason my try, except setup here doesn't work.</p>
  
  <p>When I run this, it gives the error:
  <strong>WindowsError: [Error 32] The process cannot access the file because it is being used by another process:</strong></p>
  
  <pre><code>dir_src = 'D:\\images'
  folderlist = os.listdir(dir_src)
  
  for folder in folderlist:
      flag = False
      dir_src_fine = dir_src + '\\' + folder
      filelist = os.listdir(dir_src_fine)
  
      for x in filelist:
          flag = False
          name = dir_src_fine + "\\" + x
  
          try:
              im = Image.open(name).convert('RGB')
              im.close()
  
          except IOError:
              os.remove(name)
  </code></pre>