Windows XP Changes Filename SortingBy Neil J. Rubenking | Print
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
Here's a fix if Win XP's new (and dramatically different) file-sorting algorithm wreaks havoc on legacy programs.
Microsoft changed the filename sort algorithm in Windows XP, making it different from all previous versions. The only reference I've found is the Microsoft Knowledge Base Article Q318872 that addresses an incorrect sort order in Windows XP. This article in turn refers to a new Windows API function called StrCmpLogicalW, which implements the new sort algorithm.
I have almost 5,000 filenames that were constructed so that Windows Explorer would sort the filenames chronologically (using the old character-by-character sort algorithm). These files have been distributed across the United States. I now have the task of renaming all these files so that Windows XP will sort them chronologically and still have them sort correctly in previous Windows versions.
There is a small Registry fix that will restore the old sort order, but I can't rely on all my users installing this fix. I want to bring this to the attention of computer users. As users develop program tasks that require filename sorts, they need to be aware of this unpublicized Microsoft change that will directly impact their desired end results.
There are actually two distinct points here. First, Windows XP has a new sorting algorithm for filenames. Second, this algorithm may break down when filenames contain ten or more consecutive digits. The problem with long strings of digits has been fixed in the latest Windows XP service pack, but the change to the sort algorithm remains.
In previous versions of Windows, filenames are sorted text-wise, character by character. File1.txt, File10.txt, and File100.txt are all placed before File2.txt, because the digit 1 comes before the digit 2. Most users have grown accustomed to zero-padding sequential numbers in filenamesFile010.txt correctly comes after File002.txt. Under Windows XP, though, each block of consecutive digits is treated as a number and sorted as such. Even without zero-padding, File10.txt comes after File2.txt.
For most users, this will be a benefit, not a problem. If you're one of the few who have developed solutions that rely on the old order, you can make the Registry tweak mentioned above. Launch REGEDIT from the Start menu's Run dialog and navigate to HKEY_LOCAL_ MACHINE\Software\Microsoft\Windows\ Currentversion\Policies\Explorer. In the right-hand pane, find or create a DWORD value named NoStrCmpLogical. Double-click it and set its data to 1 (no matter whether it's hex or decimal). Now Win XP will sort filenames the old way.