Message203285
shutil.rmtree works nice on Windows until it hits file with read only attribute set. Workaround is to provide a onerror parameter as a function that checks and removes file attribute before attempting to delete it. Can option to delete read_only files be integrated in shutil.rmtree?
Example output in In Python 2.7:
shutil.rmtree("C:\\2")
Traceback (most recent call last):
File "<pyshell#60>", line 1, in <module>
shutil.rmtree("C:\\2")
File "C:\Program Files (x86)\Python.2.7.3\lib\shutil.py", line 250, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Program Files (x86)\Python.2.7.3\lib\shutil.py", line 248, in rmtree
os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'C:\\2\\read_only_file.txt'
Example output in In Python 3.3:
shutil.rmtree("C:\\2")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
shutil.rmtree("C:\\2")
File "C:\Program Files (x86)\Python.3.3.0\lib\shutil.py", line 460, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Program Files (x86)\Python.3.3.0\lib\shutil.py", line 367, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Program Files (x86)\Python.3.3.0\lib\shutil.py", line 365, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\2\\read_only_file.txt' |
|
Date |
User |
Action |
Args |
2013-11-18 12:11:11 | ivan.radic | set | recipients:
+ ivan.radic |
2013-11-18 12:11:11 | ivan.radic | set | messageid: <1384776671.66.0.696428447361.issue19643@psf.upfronthosting.co.za> |
2013-11-18 12:11:11 | ivan.radic | link | issue19643 messages |
2013-11-18 12:11:11 | ivan.radic | create | |
|