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.
master
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
1 changed files with 6 additions and 2 deletions

View File

@ -462,7 +462,9 @@ class Path:
''' '''
directories = [] 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) child = self.with_child(entry.name, _case_correct=self._case_correct)
if entry.is_dir(): if entry.is_dir():
directories.append(child) directories.append(child)
@ -477,7 +479,9 @@ class Path:
''' '''
Yield directories from this directory and subdirectories. 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(): if entry.is_dir():
child = self.with_child(entry.name, _case_correct=self._case_correct) child = self.with_child(entry.name, _case_correct=self._case_correct)
yield child yield child