0% found this document useful (0 votes)
6 views

Algorithm - What Is The First Character in The Sort Order Used by Windows Explorer - Stack Overflow

Uploaded by

raparigol
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Algorithm - What Is The First Character in The Sort Order Used by Windows Explorer - Stack Overflow

Uploaded by

raparigol
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

https://stackoverflow.

com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

What is the first character in the sort order used by


Windows Explorer?
Asked 10 years ago Active 1 year, 10 months ago Viewed 107k times

For example, in a Windows folder, if we create some files and name them 1.html, 2.txt,
3.txt, photo.jpg, zen.png the order will be as is. But if we create another file with the name
56 _file.doc it will be placed at the top. (considering we sort by name in descending order)

likewise, what would be the character that would be considered as the first, such that if i
use that character, it would place the file on top of the hierarchy?
17
windows algorithm programming-languages char special-characters

edited Nov 29 '10 at 8:46 asked Nov 27 '10 at 7:07


AakashM shxfee
58k 13 140 178 4,597 4 27 28

1 Good question... have edited your title to clarify that it is Windows Explorer you are interested in.
– AakashM Nov 29 '10 at 8:47

I developed that issue after over trying OOP. now i have phobia on being too specific.. :p thanks.
– shxfee Dec 2 '10 at 11:41

There's a thread in answers.microsoft.com. – Det Mar 29 '15 at 22:08

9 Answers Active Oldest Votes

The first visible character is '!' according to ASCII table.And the last one is '~' So "!file.doc"
or "~file.doc' will be the top one depending your ranking order. You can check the ascii
31 table here: http://www.asciitable.com/

edited Nov 27 '10 at 7:17 answered Nov 27 '10 at 7:12


limitfan
834 1 8 20

03/12/2020 10:47 1 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

3 The various whitespace characters come first; assuming you don't want new lines in your file name,
tab < space < ! . – Antal Spector-Zabusky Nov 27 '10 at 18:01

3 I'm looking at a folder structure right now with my very eyes were - is alphabetized before ! – Eric
Sep 30 '11 at 17:08

43 All punctuation (no matter what codepoint) sorts before numbers before letters, plus special
behaviour for dashes. Not ASCII order. Thus: !file #file $file (file [file _file {file ~file +file ☺file 1file
9file 66file afile -afile –afile —afile zfile -zfile –zfile —zfile – Nigel Touch Mar 7 '14 at 21:47

4 I agree with @NigelTouch, this is not ASCII order, try to rename abc to ~abc, check ~ character in
ascii table and you'll see that it's not ascii order. – yohann.martineau Jul 23 '14 at 10:04

9 Wrong answer, never tested by the answerer, yet gets 24 votes. – Jim Balter Oct 26 '18 at 2:57

I had the same problem. I wanted to 'bury' a folder at the bottom of the sort instead of
bringing it to the top with the '!' character. Windows recognizes most special characters as
27 just that, 'special', and therefore they ALL are sorted at the top.

However, if you think outside of the English characters, you will find a lot of luck. I used
Character Map and the arial font, scrolled down past '~' and the others to the greek
alphabet. Capitol Xi, Ξ, worked best for me, but I didn't check to see which was the actual
'lowest' in the sort.

edited Dec 12 '11 at 12:18 answered Aug 23 '11 at 19:28


cosmin Chad Stilwell
20.2k 5 37 56 271 3 2

13 Beyond Greek Xi (Ξ) you'll find Omega (Ω) and finally Omega with Prosgegrammeni (ῼ). Then
you're on to Hebrew (‫ )ﭏ‬and Arabic (‫ )ﻼ‬and Chinese (终) and Klingon... – Nigel Touch Mar 7 '14 at
21:35

2 Here's a non-alphabet/letter character which sorts low: ꞈ ('MODIFIER LETTER LOW


CIRCUMFLEX ACCENT' (U+A788).) It ranks after Nigel's Arabic (‫ )ﻼ‬and before his Chinese (终)
chars. (Tested in Windows 7 in English (actually German, but set to English).) (Found here:
neowin.net/forum/topic/…) – Aaron Thoma Jul 21 '15 at 21:14

6 I like Omega Ω due to its kind of self-documenting nature as the 'very last' (after Z) char. :)
– Aaron Thoma Jul 21 '15 at 21:22

03/12/2020 10:47 2 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

If you google for sort order windows explorer you will find out that Windows Explorer
(since Windows XP) obviously uses the function StrCmpLogicalW in the sort order "by
16 name". I did not find information about the treatment of the underscore character. I was
amused by the following note in the documentation:

Behavior of this function, and therefore the results it returns, can change from
release to release. ...

edited Sep 12 '16 at 4:36 answered Nov 30 '10 at 13:20


Alan Moore hmuelner
67.1k 11 88 145 7,773 1 25 38

4 And indeed it appears to have changed. Fast forward to Windows 8, and some special characters
appear to be ignored. My old habit of prefixing a folder name with '-' to put it at the top, now doesn't
work... However, just discovered that using '=' does put my folder back at the top. Yay!
– Greg Woods May 5 '15 at 8:22

4 Microsoft was telling the truth ;-) – hmuelner May 5 '15 at 8:36

03/12/2020 10:47 3 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

Only a few characters in the Windows code page 1252 (Latin-1) are not allowed as names.
Note that the Windows Explorer will strip leading spaces from names and not allow you to
8 call a files space dot something (like ␣.txt ), although this is allowed in the file system!
Only a space and no file extension is invalid however.

If you create files through e.g. a Python script (this is what I did), then you can easily find
out what is actually allowed and in what order the characters get sorted. The sort order
varies based on your locale! Below are the results of my script, run with Python 2.7.15
on a German Windows 10 Pro 64bit:

Allowed:

32 20 SPACE
! 33 21 EXCLAMATION MARK
# 35 23 NUMBER SIGN
$ 36 24 DOLLAR SIGN
% 37 25 PERCENT SIGN
& 38 26 AMPERSAND
' 39 27 APOSTROPHE
( 40 28 LEFT PARENTHESIS
) 41 29 RIGHT PARENTHESIS
+ 43 2B PLUS SIGN
, 44 2C COMMA
- 45 2D HYPHEN-MINUS
. 46 2E FULL STOP
/ 47 2F SOLIDUS
0 48 30 DIGIT ZERO
1 49 31 DIGIT ONE
2 50 32 DIGIT TWO
3 51 33 DIGIT THREE
4 52 34 DIGIT FOUR
5 53 35 DIGIT FIVE
6 54 36 DIGIT SIX
7 55 37 DIGIT SEVEN
8 56 38 DIGIT EIGHT
9 57 39 DIGIT NINE
; 59 3B SEMICOLON
= 61 3D EQUALS SIGN
@ 64 40 COMMERCIAL AT
A 65 41 LATIN CAPITAL LETTER A
B 66 42 LATIN CAPITAL LETTER B
C 67 43 LATIN CAPITAL LETTER C
D 68 44 LATIN CAPITAL LETTER D
E 69 45 LATIN CAPITAL LETTER E
F 70 46 LATIN CAPITAL LETTER F
G 71 47 LATIN CAPITAL LETTER G
H 72 48 LATIN CAPITAL LETTER H
I 73 49 LATIN CAPITAL LETTER I
J 74 4A LATIN CAPITAL LETTER J
K 75 4B LATIN CAPITAL LETTER K

Forbidden:

\x00 0 00 NULL CHAR


\x01 1 01 START OF HEADING
\x02 2 02 START OF TEXT
\x03 3 03 END OF TEXT
\x04 4 04 END OF TRANSMISSION
\x05 5 05 ENQUIRY

03/12/2020 10:47 4 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

\xa7 167 A7 SECTION SIGN

I know it's an old question, but it's easy to check this out. Just create a folder with a bunch
of dummy files whose names are each character on the keyboard. Of course, you can't
6 really use \ | / : * ? " < > and leading and trailing blanks are a terrible idea.

If you do this, and it looks like no one did, you find that the Windows sort order for the
FIRST character is 1. Special characters 2. Numbers 3. Letters

But for subsequent characters, it seems to be 1. Numbers 2. Special characters 3. Letters

Numbers are kind of weird, thanks to the "Improvements" made after the Y2K non-event.
Special characters you would think would sort in ASCII order, but there are exceptions,
notably the first two, apostrophe and dash, and the last two, plus and equals. Also, I have
heard but not actually seen something about dashes being ignored. That is, in fact, NOT
my experience.

So, ShxFee, I assume you meant the sort should be ascending, not descending, and the
top-most (first) character in the sort order for the first character of the name is the
apostrophe.

As NigelTouch said, special characters do not sort to ASCII, but my notes above specify
exactly what does and does not sort in normal ASCII order. But he is certainly wrong about
special characters always sorting first. As I noted above, that only appears to be true for
the first character of the name.

answered Dec 14 '14 at 18:50


Douglas Chapman
61 1 1

03/12/2020 10:47 5 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

I know there is already an answer - and this is an old question - but I was wondering the
same thing and after finding this answer I did a little experimentation on my own and had
3 (IMO) a worthwhile addition to the discussion.

The non-visible characters can still be used in a folder name - a placeholder is inserted -
but the sort on ASCII value still seems to hold.

I tested on Windows7, holding down the alt-key and typing in the ASCII code using the
numeric keypad. I did not test very many, but was successful creating foldernames that
started with ASCII 1, ASCII 2, and ASCII 3. Those correspond with SOH, STX and ETX.
Respectively it displayed happy face, filled happy face, and filled heart.

I'm not sure if I can duplicate that here - but I will type them in on the next lines and submit.

☺foldername

☻foldername

♥foldername

answered Aug 21 '13 at 19:13


Jimbugs
189 4

03/12/2020 10:47 6 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

Although the answer with "!" was chosen as the correct answer, this is NOT true. I´m not
sure about Windows Explorer in Windows 10/8.1/8, but I am certain concerning Windows 7
3 and XP.

The character that moves your filename to the very top is "'" (alt+39), and second best is
"-" (the minus sign).

But sorting order in Windows Explorer is more complicated - it depends on the filename-
lenght also, and numbers are treated very special.

The second character (and the following) is treated different. Here you often go best with a
" " (spacebar), followed by the characters mentioned above, but you´ll have to try out,
because it´s not so easy to find out the exact algorithm:

Here is an example for the correct sorting order for your understanding:

1. file: "'"

2. file: "''" (longer filename)

3. file: "'''" (and so on)

4. file: "-"

5. file: "--"

6. file: "---" (and so on)

7. file: "- -" (spacebar used)

8. file: "' '" (spacebar two times, therefore longer filename)

9. file: "' ' '" (most top character, but longer filename!)

10. file: "'' 0" (shorter filename, but chars like numbers came in)

Another example:

1. "'' aaaa" ("'" is better than spacebar and spacebar is better than "a")

2. "'' aaaaa"

3. "' aaaaaa"

Same filelenght:

1. "-- aa" (spacebar comes before "-" in this case!)

2. "---aa"

3. "--aaa"

Finally the very special logic when it comes to numbers:

1. "0000000"

2. "0"

03/12/2020 10:47 7 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

03/12/2020 10:47 8 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

From my testing, there are three criteria for sorting characters as described below. Aside
from this, shorter strings are sorted above longer strings that start with the same
3 characters.

Note: This testing only looked at the first character sorting and did not look into edge
cases described by this answer, which found that, for all characters after the first character,
numbers take precedence over symbols (i.e. the order is 1. Symbols 2. Numbers 3. Letters
for first character, 1. Numbers 2. Symbols 3. Letters after). This answer also indicated that
the Unicode/ASCII layer of sorting might not be entirely consistent. I'll update this answer if
I get time to look into these edge cases.

Note: It's important to note that sorting order might be subject to change as described by
this answer. It is not clear to me though the extent to which this actually ever changes. I've
done this testing and found it to be valid on both Windows 7 and Windows 10.

Symbols
Latin (ordered by Unicode value (U+xxxx))
Greek (ordered by Unicode value (U+xxxx))
Cyrillic (ordered by Unicode value (U+xxxx))
Hebrew (ordered by Unicode value (U+xxxx))
Arabic (ordered by Unicode value (U+xxxx))

Numbers
Latin (ordered by Unicode value (U+xxxx))
Greek (ordered by Unicode value (U+xxxx))
Cyrillic (ordered by Unicode value (U+xxxx))
Hebrew (ordered by Unicode value (U+xxxx))
Arabic (ordered by Unicode value (U+xxxx))

Letters
Latin (ordered by Unicode value (U+xxxx))
Greek (ordered by Unicode value (U+xxxx))
Cyrillic (ordered by Unicode value (U+xxxx))
Hebrew (ordered by Unicode value (U+xxxx))
Arabic (ordered by Unicode value (U+xxxx))

03/12/2020 10:47 9 of 10
https://stackoverflow.com/questions/4290541/what-is-the-first-character-in-the-sort-order-used-by-windows-explorer

TLDR; technically space sorts before exclamation mar, and can be used by preceding it
with ' or - (which will be ignored in sorting), but exclamation mark follows right after space,
0 and is easier to use.

On windows 7 at least, a minus sign (-) and (') seem to be ignored in a name except for
one quirk: in a name that is otherwise identical, the ' will be sorted before -, for example:
(a'a) will sort above (a-a)

Empty string will sort above everything else, which means for example aa will sort above
aaa because the 'empty string' after two a letters will sort before the third 'a'.

This also means that aa will be sorted above a'a because the 'empty string' between two a
letters will sort above the ' mark.

What follows then is, ' alone will sort first, because technically it's an empty string. However
adding for example letters behind it will sort the name as if the ' didn't exist.

Since the first 'unignored' character (as far as I know) is space, in case you want to sort
'real names' above others, the best way to go would be ' followed by space, and then the
name you want to actually use. For example: (' first)

You can of course top that by using more than one space in the strong, such as (' firster)
and (' firstest) with two and three blanks before the f.

While minus sign sorts below ' in otherwise similar name, there's no other difference in
sorting (that I know of), and I find minus sign visually clearer, so if I want to put something
on top of list, I'd use minus followed by space, then the 'actual name', for example: (- first
file -)

If you are worried about using space on the filename, then exclamation mark (!) is the next
best thing - and since it can appear as first character on a string, it's easier to use.

edited Aug 18 '17 at 13:30 answered Aug 18 '17 at 13:23


Nogitsune
1 1

03/12/2020 10:47 10 of 10

You might also like