Windows XP Changes Filename Sorting

By Neil J. Rubenking  |  Posted 2003-09-02 Email Print this article Print


Re-Thinking HR: What Every CIO Needs to Know About Tomorrow's Workforce

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.

Fred Gould

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 filenames—File010.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.

Neil J. Rubenking Neil Rubenking served as vice president and president of the San Francisco PC User Group for three years when the IBM PC was brand new. He was present at the formation of the Association of Shareware Professionals, and served on its board of directors. In 1986, PC Magazine brought Neil on board to handle the torrent of Turbo Pascal tips submitted by readers. By 1990 he had become PC Magazine's technical editor, and a coast-to-coast telecommuter. His 'User to User' column supplied readers with tips and solutions on using DOS and Windows, his technical columns clarified fine points in programming and operating systems, and his utility articles (over forty of them) provided both useful programs and examples of programming in Pascal, Visual Basic, and Delphi. Mr. Rubenking has also written seven books on DOS, Windows, and Pascal/Delphi programming, including PC Magazine DOS Batch File Lab Notes and the popular Delphi Programming for Dummies. In his current position as a PC Magazine Lead Analyst he evaluates and reports on client-side operating systems and security solutions such as firewalls, anti-virus, anti-spyware, anti-spam and full security suites. He continues to answer questions for readers in the ongoing 'Solutions' column and in PC Magazine's discussion forums.


Submit a Comment

Loading Comments...

Thanks for your registration, follow us on our social networks to keep up-to-date