Merge pull request #3393 from SylvainCorlay/fixup-rmtree-windows

Fixup rmtree on windows
This commit is contained in:
Gil Forsyth 2019-11-26 21:00:08 -05:00 committed by GitHub
commit 761c6bdedd
Failed to generate hash of commit
2 changed files with 12 additions and 9 deletions

View file

@ -0,0 +1,5 @@
**Fixed:**
* Using rmtree on windows no longer attempts to use invalid ``rm`` command
and uses ``del`` instead.

View file

@ -26,13 +26,11 @@ def rmtree(dirname, force=False):
force : bool
If True force removal, defaults to False
"""
cmd_args = '-r'
if force:
cmd_args += 'f'
try:
if sys.platform == "win32":
cmd_args = '/S/Q'
![rmdir @(cmd_args) @(dirname)]
else:
cmd_args = '-r'
if force:
cmd_args += 'f'
![rm @(cmd_args) @(dirname)]
except PermissionError:
if sys.platform == "win32":
![del /F/S/Q @(dirname)]
else:
raise