it’s so confusing that the order changes when adding IDENTICAL strings to BOTH filenames. Is this really how it’s supposed to be?

  • Lysergid@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    5 days ago

    What you expecting called natural sorting. Mac employed natural sorting back in 90s. What you get is legitimate Alphabetical sorting which used by Linux and Windows. Natural sorting parses tokens in the string and compares them. Alphabetical sorting compares two strings by comparing individual characters at same index (position). Alphabetical sorting is quite common as it simpler to implement (or rather harder to screw up) and yields predictable results

    One of many libraries for Python which implements natural sorting https://github.com/SethMMorton/natsort

  • folekaule@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    6 days ago

    Yes. The periods are just part of the name like any other letter, so 5 is compared to m, and numbers sort before letters. You can add something like ‘.0’ to make it sort more naturally. Look up an ASCII table to get a feeling for how strings are sorted.

  • Dave@lemmy.nz
    link
    fedilink
    arrow-up
    1
    ·
    6 days ago

    I believe it’s correct. If you sort say “A”, “AA”, “AAA” then you get

    1. A
    2. AA
    3. AAA

    Because the first character is compared, which are all the same, then the second. The first one has no second character, so it comes first. The second has no third character, so it comes before the third item.

    In your scenario, you have:

    1. 5
    2. 5.5

    The first characters are the same, so it looks at the second character. Item 1 has no second character so it comes first.

    Scenario 2:

    1. 5.5 A
    2. 5 A

    The first character is the same, so it looks at the second character. The second characters are “.” and " ". The “.” comes first in the character ranking so is shown first.