Explain 'sort by name' to me

Soldato
Joined
31 May 2009
Posts
21,468
Folders within windows, where filenames are selected as 'sort by name'
When things start with letters they always manage to make it into the correct order, but where numbers exist at the start of a filename things seem to be more confusing.

Why is the sort order using 'sort by name' and 'ascending'?

0c1ffd14
then
1df7dd29
then
02acff68
 
Dunno. Going purely off your example, perhaps it ignores leading zeros if they're followed by a number, but not a letter. It's the sort of retarded logic that MS seem to enjoy.
 
I never knew it did this, interesting!

http://support.microsoft.com/kb/319827

Looks like sort by name uses StrCmpLogicalW. If you look up the API of StrCmpLogicalW:

This function's ordering schema differs somewhat from StrCmpI, which also compares strings without regard to case sensitivity. Considering digits by their numerical value—as StrCmpLogicalW does—strings are ordered as follows:

2string
3string
20string
st2ring
st3ring
st20ring
string2
string3
string20


Therefore, in your example it's ordering them as numerical. So if you take the initial numerals of your file list you get:

0
1
02

The 0 in 02 is irrelevant, therefore, the order is:

0
1
2

Hence why it is what it is, and why it's in that order :)
 
Back
Top Bottom