5

I've noticed that in Windows, when you sort files alphabetically, there's a strange thing that happens when you have file names that extend one another with spaces. For example, say you have two files, "Outline.pdf" and "Outline Revised.pdf". Since the latter has a longer name extending the former, you'd think it would come after. However, when I sort in ascending order, I get:

Alphabetical.pdf

Outline Revised.pdf

Outline.pdf

Outline_Revised.pdf

Outline-Revised.pdf

Sorting

I've added extra files to illustrate in more detail what is going on. When you have a space between "Outline" and "Revised", the file is sorted before "Outline.pdf"; however, when this space is switched to an underscore or a hyphen, this no longer happens.

My question is: why does Windows treat spaces like this when sorting? I.e., why do spaces take priority over the end of a name?

Less importantly, is there a way to change this?

EDIT: Added file extensions for more context.

EDIT 2: Added more files for a clearer example

2
  • 2
    A space in ASCII is 32, as to the reason Windows sorts the way it does, because a Windows developer decided to write the sort that way. In you example it's not clear if your using ascending or descending. Without a file extension it's difficult to determine that.
    – Ramhound
    Mar 23, 2020 at 19:31
  • Outline would indeed come before Outline Revised but Outline. would come after because . comes after space. So Outline.pdf comes after Outline Revised.pdf
    – slebetman
    Mar 24, 2020 at 11:19

1 Answer 1

8

Operating systems can really only use one of two basic methods, ASCII sorting or Natural sorting

ASCII gives this

enter image description here
pic credit - http://support.ecisolutions.com/doc-ddms/help/reportsmenu/ascii_sort_order_chart.htm

which takes each single element & applies sort rules, without any other interpretation.

Natural sort attempts to handle such as numerical sequences in a more logical order - so 9, 10, 11 rather than 10, 11, 9
It can also handle more 'library-style' sorting, treating various whitespace characters as equal.

Windows sort would appear to be using ASCII, where space comes before underscore, so sorts first.

You could equally ask, 'Why does windows sort folders to the top with files underneath, when a rational mind would sort naturally?" - someone picked that way, no other reason. Other OSes do sort naturally… which gives issues with such as UUIDs, which ought to be sorted ASCII. There is no perfect solution.

I hadn't included that the example files will have invisible 'dot three' extensions.
The . [dot] will sort after space, ASCII.
This was before the question was edited to explicitly show the .3

Empirically, both Mac & Win10 seem to do some kind of natural sort these days - I was sure Windows didn't used to & I don't use Win much so had to have a look.
This is how they each sort the same files…

enter image description here

They both seem to agree that underscore comes before dash, in contradiction to the strict ASCII sort, but disagree on what to do with the period.

14
  • 1
    I didn't mean to ask why "Outline Revised.pdf" sorts before "Outline_Revised.pdf"; I wanted to know why "Outline Revised.pdf" sorts before "Outline.pdf". It can't be because a space comes before a period in ASCII, because "Outline-Revised.pdf" sorts after "Outline.pdf"
    – Sambo
    Mar 23, 2020 at 20:07
  • 1
    @Sambo, I believe the question is answered, in the list 'space' is at the top and therefore is used before any other character. Period is next, then underscore. In case one, space>. is correct. In case two, period>underscore is correct. Yes?
    – Ack
    Mar 23, 2020 at 20:19
  • 1
    @Ack I see what you mean. I didn't think that was the correct reason at first, because when I replaced the space for a hyphen, the hyphen was sorted after the period even though it comes before it in your table. However, with parentheses it sorts it before, so it makes sense that the period is affecting the sorting, which I hadn't realized.
    – Sambo
    Mar 23, 2020 at 20:48
  • 2
    In short, that table can't exactly be what they're using for sorting. However, you're correct that my error was not taking into account the extension of the file when sorting.
    – Sambo
    Mar 23, 2020 at 20:50
  • 2
    Actually, since at least Windows 10 (if not earlier), Windows uses natural sorting, so foo_9.txt does come before foo_10.txt. Or IMG (3).jpg comes before IMG (10).jpg. Mar 24, 2020 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .