From 31156aa67cdfe27e35cf551f019e6e959b1178a7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 4 Jan 2022 12:47:17 -0800 Subject: [PATCH] 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. --- voussoirkit/pathclass.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index df3329f..7d1f8b7 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -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