Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Weird file name sorting order in folder explorer window

76 views
Skip to first unread message

Paul Randall

unread,
Mar 31, 2008, 11:45:41 AM3/31/08
to
Hi,
I have a little project where I want the file names to be strings of
hexidecimal numbers, like 0000.txt and A000.txt. I want the user to
be able to display the folder containing hundreds of these files in
view-details mode, sorted alphabetically, and easily find a particular
file. With these hexidecimally named files, the sorting is weird and
unintuitive to me (I'd almost call the sorting dyslectic) , and any
particular file is difficult to find.

Question: Is there any scripting (or non-scripting) way to make a
folder explorer window display the file names in plain ASCII ascending
order?

Example:
The following script creates 61 zero-byte text files:
Option Explicit
Dim i, j, sFileName
For j = 0 To 3
For i = 0 To 15
sFileName = Right("000" & Hex(i * (16 ^ j)), 4) & ".txt"
With CreateObject("Scripting.FileSystemObject")
.CreateTextFile(sFileName, True, False).Write("")
End With
Next 'i
Next 'j
MsgBox "All Done"

This creates one file named 0000.txt and four groups of 15 files with
a single non-zero hexidecimal digit in column 4, 3, 2, and 1
respectively, for a total of 61 files. The order in which they are
created is the order in which they are sorted by the 'dir /on'
command, and this is also the order I'd like to see them in the
explorer window. A folder explorer window sorts them differently, as
follows:

0000.txt
00A0.txt
0A00.txt
000A.txt
same pattern of 3 files repeated for B, C, D, E, and F
0001.txt
0002.txt
...
0008.txt
0009.txt
same pattern of 9 files repeated with the non-zero numeric digit in
columns 3, 2, and 1.
A000.txt
B000.txt
C000.txt
D000.txt
E000.txt
F000.txt

I'm running WXP Pro SP2, but get the same bad results on WXP Home with
no service packs or updates installed. Adding a fixed alphabetic
character at the beginning or end of the file name does not change the
weird sorting order. W98SE displays the files sorted properly in an
explorer window.

Thanks for any help you can give me.

-Paul Randall


Richard Mueller [MVP]

unread,
Mar 31, 2008, 1:08:47 PM3/31/08
to
I see the same behaviour in Vista. I cannot make any sense out of it, or see
any way to fix it.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Paul Randall" <paul...@cableone.net> wrote in message
news:u$puAa0kI...@TK2MSFTNGP02.phx.gbl...

Tom Lavedas

unread,
Mar 31, 2008, 1:36:10 PM3/31/08
to
On Mar 31, 1:08 pm, "Richard Mueller [MVP]" <rlmueller-

nos...@ameritech.nospam.net> wrote:
> I see the same behaviour in Vista. I cannot make any sense out of it, or see
> any way to fix it.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -http://www.rlmueller.net
> --
>
> "Paul Randall" <paulr...@cableone.net> wrote in message

My XPPSP2 system sorts it correctly. The only thing I can think of is
that I have it set to Windows Classic format (no web content in folder
display).

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Tom Lavedas

unread,
Mar 31, 2008, 2:05:46 PM3/31/08
to

Actually, I was able to get it to mess up. I changed the display from
Detail to Icon a in non-classic mode snd everything went berserk. The
only thing that I could do to restore order was to delete the folder
and recreate it in my standard for all folders - Details. Then it was
sorted correctly. It seems to be a bug in the non-classic formatted
window when any change is made. But operation in the Windows classic
mode does not create any problems. However, once it is messed up
switching into classic mode does not fix the problem. Once the order
is corrupted, it appears to be permanent. I guess it's related to a
registry setting.

Luuk

unread,
Mar 31, 2008, 2:17:01 PM3/31/08
to
Tom Lavedas schreef:


it seem not to have to do with the classic format, as on my XPPSP2 is
also displayed wrong, and i also use Classic format.

it also seems that is has nothing to do with your script, because if
files a re created manually. the order stays as:
0000.txt
00A0.txt
0A00.txt
000A.txt

--
Luuk

Paul Randall

unread,
Mar 31, 2008, 2:17:50 PM3/31/08
to

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:8f7a28dc-7998-469a...@m73g2000hsh.googlegroups.com...

Tom & Richard,

Thanks for letting me know that my system isn't the problem and it is
at least possible to have WXP sort non-dyslexically. I tried manually
switching to classic folder view from control panel -> Folder Options
'Use Windows classic folders' on the general tab. That did not fix
it, but I haven't tried rebooting yet. I'd prefer not to have to
reboot to get the proper sort, and be able to easily get back the
person's preferences. I will play with it some more....

I've been messing with Unicode a little, and now I understand why the
order of the files listed at http://unicode.org/charts/PDF/?C=N;O=A
seems strange.

-Paul Randall


Keith Miller (MVP)

unread,
Mar 31, 2008, 3:19:14 PM3/31/08
to
Have you tried adding 'NoStrCmpLogical' REG_DWORD = 1 to either:

[HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]

or

[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]

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


--
Good Luck,

Keith
Microsoft MVP [Windows Shell/User]

"Paul Randall" <paul...@cableone.net> wrote in message

news:uBzPCv1...@TK2MSFTNGP04.phx.gbl...

Al Dunbar

unread,
Mar 31, 2008, 11:52:29 PM3/31/08
to
Totally bizarre. I very often sort files in explorer, often having explorer
configured to show common tasks rather than classic windows, and have never
noticed any such anomaly. I guess I just happen to use a naming convention
that does not cause the problem, as I have just confirmed the irrational
order, and it happens to me even in a newly created folder that has
defaulted to the classic style.

Thanks for the info, Keith. That KB article would seem to suggest that the
more recent versions try to sort filenames numerically, if at all possible.
Although we have all struggled in the past with finding files with names
like 8, 9, 10, 11 being sorted as 10,11,8,9. But just because a filename
contains a digit (even a leading one) does not mean that its creator wants
this kind of sorting.

Strangely enough, in the example Paul provides, the sort order seems truly
irrational, but repeatable. It is as if the leading digit causes a different
sorting method to operate, but one that, unfortunately, is incapable of
reverting to a character-based sort when it finds the filename to be other
than completely numeric.

I tried the same sequence with a non-hex letter prefixing the name, i.e.
"z00A*.txt" and etc, and it still resulted in the odd order. I then changed
all of the zeros to nines and the sort order became more rational. I then
changed the nens to eights and ran my file creation script again, and this
is how it sorts:

z8A88.txt
z9A99.txt
z88A8.txt
z99A9.txt

and etc. Now I'm getting dizzy...


/Al

" Keith Miller (MVP)" <k.mi...@NOSPAM.mchsi.com> wrote in message
news:eDoJcQ2k...@TK2MSFTNGP02.phx.gbl...

Paul Randall

unread,
Apr 1, 2008, 8:03:18 PM4/1/08
to

" Keith Miller (MVP)" <k.mi...@NOSPAM.mchsi.com> wrote in message
news:eDoJcQ2k...@TK2MSFTNGP02.phx.gbl...
> Have you tried adding 'NoStrCmpLogical' REG_DWORD = 1 to either:
>
> [HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
>
> or
>
> [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer]
>
> http://support.microsoft.com/kb/319827

Hi Keith,

Thank you for the link. I have tried it for the all users key, but
not current user key, and it works well. One minor problem is that
changing this value does not take effect until explorer is restarted.

For example, suppose I am the only one logged on to the computer and I
change the NoStrCmpLogical value. Even if I close all explorer
windows, I do not see the change when I open an explorer window. If I
switch users without logging off or shutting down, the new user does
see the change. If I then switch back to the original account, I
don't see the change because the old explorer is still running for
this user. If I manually use task manager to terminate explorer.exe,
and restart it, I do see the change, but info on what folders were
open is not retained.

Does anyone know of a scripting way to force Explorer.exe to refresh
its initialization from the registry, or to shut down and restart
explorer gracefully (so that it retains all open folders for example)
from a VBScript?

-Paul Randall


0 new messages