title: How to delete read-only files easily?
body: <p>I want to make my code delete all the content of the temporary and prefetch folders, however some of the files are read-only, so the code returns an error 5: access denied.</p>
  
  <pre class="lang-py prettyprint-override"><code>def deletetemp():
      try:
          for root2, dirs, files in os.walk(r'C:\Windows\Temp'):
              for f in files:
                  os.unlink(os.path.join(root2, f))
              for d in dirs:
                  shutil.rmtree(os.path.join(root2, d))
          for root2, dirs, files in os.walk(r'C:\Windows\Prefetch'):
              for f in files:
                  os.unlink(os.path.join(root2, f))
              for d in dirs:
                  shutil.rmtree(os.path.join(root2, d))
          for root2, dirs, files in os.walk(r'C:\Users\*myusername*\AppData\Local\Temp'):
              for f in files:
                  os.unlink(os.path.join(root2, f))
              for d in dirs:
                  shutil.rmtree(os.path.join(root2, d))
          x.configure(text="Temporary/Prefetch files deleted!")
      except Exception as e:
          x.configure(text=str(e))
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>Exception in Tkinter callback
  Traceback (most recent call last):
    File "C:/Users/*myusername*/.PyCharmCE2019.1/config/scratches/scratch.py", line 10, in deletetemp
      os.unlink(os.path.join(root2, f))
  PermissionError: [WinError 5] Access is denied: 'C:\\Windows\\Temp\\vcredist_x86.exe'
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/1073382/9681255">This is the place I got the code from.</a></p>
  
  <p>If you didn't notice yet, I'm a noob in coding. Please try and provide simple answers (though, of course, don't do the code <em>entirely</em> for me). And also, I did look myself for an answer, but failed finding one. If there is one somewhere, please just redirect me! I'll take a look at it and try and make something out of it.</p>