[issue28564] shutil.rmtree is inefficient due to listdir() instead of scandir()
Josh Rosenberg
report at bugs.python.org
Mon Oct 31 12:37:10 EDT 2016
Josh Rosenberg added the comment:
You need to cache the names up front because the loop is unlinking entries, and readdir isn't consistent when the directory entries are mutated between calls. https://github.com/kripken/emscripten/issues/2528
FindFirstFile/FindNextFile likely has similar issues, even if they're not consistently seen (due to DeleteFile itself not guaranteeing deletion until the last handle to the file is closed).
scandir might save some stat calls, but you'd need to convert it from generator to list before the loop begins, which would limit the savings a bit.
----------
nosy: +josh.r
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28564>
_______________________________________
More information about the Python-bugs-list
mailing list