WebUI: wrong sorting by name?

Support intro

Nextcloud version (eg, 20.0.5): 23.0.3
Operating system and version (eg, Ubuntu 20.04): official docker
Apache or nginx version (eg, Apache 2.4.25): apache image
PHP version (eg, 7.4): 8.x

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): y

Steps to replicate it:

  1. choose existing folder with some files
  2. create new .md file
  3. use same naming convention for existing and new files (in my case yyyymmdd_.

I looks like new files are sorted between of existing files when sorted by name - but the name following ** yyyymmdd_.** should make files sort by date prefix… (sort by modification date works as expected)

somebody aware of the issue? what is the problem?

I guess this is because Nextcloud uses a “Natural Sort Order” instead of a strictly alphabetical one…

https://en.wikipedia.org/wiki/Natural_sort_order

…and if I understand the system correctly, 20180115 is sorted after 202301 because it is a larger number.

EDIT: you can test this on the command line:

using the ls command with the default alphabetical order:

$ ls -l
insgesamt 0
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221201_hjdjhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221202_djhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221210_dfsfjskfjsdjhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 202301_dfsfjskfjsdjhasdad

using the ls command with the -v option for a natural sort of (version) numbers within text:

$ ls -lv
insgesamt 0
-rw-r--r-- 1 user user 0  3. Jan 06:44 202301_dfsfjskfjsdjhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221201_hjdjhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221202_djhasdad
-rw-r--r-- 1 user user 0  3. Jan 06:44 20221210_dfsfjskfjsdjhasdad

you must be right, thank you! looks I have to adopt another naming convention for my file :frowning: adding a character e.g. dot between date parts makes it sort right!

“Wrong” (natural) sorting yyyymmdd:
image

Right sorting yyyy.mm.dd:

For the reference - the problem arises from time to time and even long-living Github issue was created 2019 (and still open)

1 Like