1

I want do delete a directory with python. I used this:

import shutil
shutil.rmtree('path/to/dir', ignore_errors=True)

but when I go into the folder, there is still a folder. (Its a .git folder which has content)

How can I also delete this directory too?

I already searched and tested many other posts but all didn't work like it should.

chraebsli
  • 184
  • 12
  • What does happens if you do `shutil.rmtree('path/to/dir', ignore_errors=False)`? – Daweo Mar 15 '21 at 14:23
  • If you set ignore errors to false, what errors pop up? There might be some info on what is going wrong – Pietro Mar 15 '21 at 14:23
  • @Daweo It gives a permission error on a file – chraebsli Mar 15 '21 at 14:26
  • @NicholasKrebs this mean you attempt to remove file which you are not allowed to remove – Daweo Mar 15 '21 at 14:27
  • @Pietro `PermissionError: [WinError 5] Zugriff verweigert: 'path/to/folder\\.git\\objects\\pack\\pack-f29a84ca6bef2ed3fa9e877d283bd0bf3075519a.idx'` its german it means Access denied – chraebsli Mar 15 '21 at 14:27
  • @Daweo then theres no way to delete it? – chraebsli Mar 15 '21 at 14:28
  • @NicholasKrebs yes, unless you are able to somewhat grant right to do so. – Daweo Mar 15 '21 at 14:33
  • @Daweo yes I think I can. Then how I do it with python? – chraebsli Mar 15 '21 at 14:36
  • @NicholasKrebs then change permissions in files that remained, so they can be removed and then `shutil.rmtree` should work as required – Daweo Mar 15 '21 at 14:42
  • [Here](https://stackoverflow.com/a/2656405/2237151) there is a suggested approach, but I cannot test it (my Windows installation broke and I never bothered to reinstall it :D). – Pietro Mar 15 '21 at 15:47

0 Answers0