Sort scandir entries.

In spinal.walk sorting is optional because there I prioritize
configurability and speed, but for pathclass.walk I think it
makes sense to prioritize comfort and just-works results.
This commit is contained in:
voussoir 2022-01-04 12:47:17 -08:00
parent d3d5bd1fa2
commit 31156aa67c
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -462,7 +462,9 @@ class Path:
'''
directories = []
for entry in os.scandir(self):
entries = os.scandir(self)
entries = sorted(entries, key=lambda e: os.path.normcase(e.name))
for entry in entries:
child = self.with_child(entry.name, _case_correct=self._case_correct)
if entry.is_dir():
directories.append(child)
@ -477,7 +479,9 @@ class Path:
'''
Yield directories from this directory and subdirectories.
'''
for entry in os.scandir(self):
entries = os.scandir(self)
entries = sorted(entries, key=lambda e: os.path.normcase(e.name))
for entry in entries:
if entry.is_dir():
child = self.with_child(entry.name, _case_correct=self._case_correct)
yield child