Windows alphabetical file sorting: why do spaces have special treatment

filenamessortingwindows 10

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

Best Answer

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.

Related Question