Sort by filename--works for dirs and files - crossword.koplugin - Unnamed repository; edit this file 'description' to name the repository. (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules (DIR) README (DIR) LICENSE --- (DIR) commit 0de2de0ffea0100f44b8bc9d46ba208611ea9289 (DIR) parent 1165a742ef81e4a19b93e9d7873ca67135aeff50 (HTM) Author: Scarlett <social@scarlettmcallister.com> Date: Sun, 7 May 2023 11:31:37 -0300 Sort by filename--works for dirs and files Diffstat: M library.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- (DIR) diff --git a/library.lua b/library.lua @@ -33,7 +33,7 @@ function Library:getFilesInDirectory(path_to_dir) return items end - for f in iter, dir_obj do + for f in iter, dir_obj do local attributes = lfs.attributes(("%s/%s"):format(path_to_dir, f)) if attributes.mode == "directory" or attributes.mode == "file" @@ -54,6 +54,11 @@ function Library:getFilesInDirectory(path_to_dir) end end + table.sort(items, function(a, b) + local fn = sort.natsort_cmp() + return fn(a.filename, b.filename) + end) + return items end @@ -67,11 +72,6 @@ end function Library:showDirectoryView(path_to_directory) local directory_items = self:getFilesInDirectory(path_to_directory) - - table.sort(directory_items, function(a, b) - local fn = sort.natsort_cmp() - return fn(a.title, b.title) - end) local kv_pairs = {} for key, item in ipairs(directory_items) do table.insert(kv_pairs, {