Problems with filename sorting order in various programs

I am trying to prepare a set of images for display in an image viewer slideshow. I have given the files names which should be sorted in alpha-numeric order and display in the correct sequence. When I use the Unix “ls” command, their order is exactly what I want and would expect. However, I am consistently getting several names in the wrong order in software working with those names. This happens in gwenview, ritstretto, showfoto and gthumb. I have the same problem in file viewers dolphin and thunar. Even file selector boxes display the names in the wrong order. There are 84 files in the directory and most are correctly ordered except for this section in the middle of the list:


Can anyone suggest what I need to do to display the files in the wanted order?

I am using Leap 42.1 and XFCE

To begin with, there is no “right” or “wrong” here, except from your personal viewpoint. It s either sorted to ASCII or to some other policy (often called “logical” by some typical end-user GUI programs).
E.g. with the numbers 1-12:
ASCII: 1 10 11 12 2 3 4 5 6 7 8 9
logical 1 2 3 4 5 6 78 10 11 12
In many lists the latter is accepted by the user as “logical” without further notice. But this “logical” sort depends on a lot of assumptions about what is logical from the application designer. It might be that an application does have a switch.

That said, I tried to find where your list goes “wrong” (not ASCII), but failed with a headache. Thus I copied it to a file and sorted it to another file and ten used diff:

henk@boven:~/test/sp> diff in out
> /home/photos/grandma/20040925-DSC00835.jpg
< /home/photos/grandma/201000-30-Print.jpg
< /home/photos/grandma/201000-31-Print.jpg
< /home/photos/grandma/201600-32-Print.jpg
< /home/photos/grandma/20040925-DSC00835.jpg
> /home/photos/grandma/201000-30-Print.jpg
> /home/photos/grandma/201000-31-Print.jpg
> /home/photos/grandma/201600-32-Print.jpg

in the hope that others now see where you have your problem.

IMHO, when you want things sorted, you must start from a common aspect to sort t on. In this case it looks as if you want sorted according to date, but there is not a normalized format for the date in your file names. That should be your first concern.

When these JPEG pictures still have the date/time the picture is token in the internal JPEG information, the tool jhead can be off help here. I allows you to change the file name using the internal date. Thus e.g. make them all yyyymmdd-hhmmss-someting.jpeg

Thanks for that. I was unaware that any order other than simple ASCII or UTF-8 existed as a formal feature for ordering file names. I have had to pad numbers with zeros in front to ensure correct sorting in the past. So all I needed to do here was to add extra trailing zeros in those names where I did not have a month and day in the file name. Easily solved when I understand the problem. Thanks so much.

Thanks for the suggestion. I had no idea that file names were normally sorted other than by ASCII or UTF-8. I have often needed to pad numbers on the left with zero to ensure that names compared correctly. In my case here, I needed to ensure that there were four zeros at the end of those leading numbers where I did not have a month and date when the photo was taken. They now sort correctly. Thanks so much for the advice.

You are welcome.

I would not call it a “a formal feature for ordering file names”. It is just an adoption of many GUI programs to the not strict logical way GUI users seem to think. lol! And I guess they are not “formal” but may differ from application to application.

OTOH I am not sure that we can expect from the end-user that (s)he understands ASCII (let alone Unicode). For the uninitiated: why should 0 come before a? And why ! before all others? Of course there are such things defined as “collating sequence” dependent of the script/language used. But again, many end-users will still say: that is not what I expected.

Those collating sequences are based on what people used before they used computers e.g. in dictionaries, etc. But even that is not hard. E.g. German uses two of them: Duden and Telefonbuch. The first being the most important German dictionary and the second being the telephone directory.

It is not easy to adapt the strict logic of IT to human expectations.

Regarding gwenview: a patch has been added recently (to kio) that makes it (and the general KDE file dialog) sort “naturally” (i.e. 10 comes after 2 instead of before).
See and
(the patch currently is only in Tumbleweed and 42.3 though, and in the devel repo, KDE:Frameworks5, of course)

In dolphin this is (and was) configurable already.

That probably wouldn’t change much in this case though, because of the separators (’-’ and ‘_’) used.