File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,25 @@ def _read_file_content(file_path: str) -> str:
149149 return f"Error reading file: { str (e )} "
150150
151151
152+ def _sort_children (children : list [dict [str , Any ]]) -> list [dict [str , Any ]]:
153+ """
154+ Sort children nodes with files first, then directories, both in alphanumerical order.
155+
156+ Parameters
157+ ----------
158+ children : list[dict[str, Any]]
159+ List of file and directory nodes to sort.
160+
161+ Returns
162+ -------
163+ list[dict[str, Any]]
164+ Sorted list with files first, followed by directories.
165+ """
166+ files = sorted ([child for child in children if child ["type" ] == "file" ], key = lambda x : x ["name" ])
167+ directories = sorted ([child for child in children if child ["type" ] == "directory" ], key = lambda x : x ["name" ])
168+ return files + directories
169+
170+
152171def _scan_directory (
153172 path : str ,
154173 query : dict [str , Any ],
@@ -329,6 +348,9 @@ def _scan_directory(
329348 result ["file_count" ] += subdir ["file_count" ]
330349 result ["dir_count" ] += 1 + subdir ["dir_count" ]
331350
351+ result ["children" ] = _sort_children (result ["children" ])
352+ return result
353+
332354 except PermissionError :
333355 print (f"Permission denied: { path } " )
334356
You can’t perform that action at this time.
0 commit comments