shutil.rmtree fails on Windows with 'Access is denied'
Posted
by Sridhar Ratnakumar
on Stack Overflow
See other posts from Stack Overflow
or by Sridhar Ratnakumar
Published on 2010-04-16T21:57:55Z
Indexed on
2010/04/16
22:03 UTC
Read the original article
Hit count: 385
In Python, when running shutil.rmtree
over a folder that contains a read-only file, the following exception is printed:
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\ActivePython32Python26\lib\shutil.py", line 221, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\ActivePython32Python26\lib\shutil.py", line 219, in rmtree
os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'build\\pyhg_trunk-win32-x86-hgtip27\\image\\feature-core\\INSTALLDIR\\tcl\\tcl8.5\\msgs\\af.msg'
Looking in File Properties dialog I noticed that af.msg
file is set to be read-only.
So the question is: what is the simplest workaround/fix to get around this problem - given that my intention is to do an equivalent of rm -rf build/
but on Windows? (without having to use unxutils or cygwin)
© Stack Overflow or respective owner