Search code examples
delphifilesortingdelphi-xe2windows-explorer

Is there a compare function for file name sorting?


Possible Duplicate:
How to get the sort order in Delphi as in Windows Explorer?

I'm looking for a function that would compare (for file sorting) exactly like Windows Explorer does. Now I'm using CompareText function, but it results in the following:

---------  /\  ---------
 AFile
 BFile
 _XFile
-----------------------

And Windows Explorer sort the same items this way (that's what I want to get):

---------  /\  ---------
 _XFile
 AFile
 BFile
-----------------------

Is there a function for this kind of comparing or should I handle this by my own ?

Thanks!


Solution

  • Windows Explorer uses StrCmpLogicalW to compare file names. The RTL/VCL does not declare this function so you need to do it yourself.

    function StrCmpLogicalW(psz1, psz2: PWideChar): Integer; stdcall;
        external 'shlwapi.dll';