Comparing and sorting Unicode file names

Using Delphi 2007 and TMS components for utils and the Unicode interface (updating to Delphi 2009 to support Unicode is not an option).

I save a list of file names in a list of strings (TTntStringList). It was sorted and not case sensitive. The standard sort procedure uses CompareStringW (LOCALE_USER_DEFAULT, NORM_IGNORECASE, ...) to compare strings (and the same for Find). However, this is a problem, because it will be equal to dummyss.txt with dummyß.txt (for example), but on NTFS it is quite legal to have these two files in the same folder, that is, they are treated as different names.

I understand that on Vista and newer, the correct way to compare file names is to use CompareStringOrdinal. Is it correct?

On systems prior to Vista, what will be right? I believe this should be CompareStringW (LOCALE_INVARIANT, ...), but I'm not quite sure.

thank

+3
source share
1 answer

Quote from an MSDN article Sorting Processing in Your Applications :

CompareStringOrdinal compares two Unicode Strings for testing binary equality, as opposed to linguistic equality. Examples of such non-linguistic strings are NTFS file names, ...

CompareStringOrdinal requires Windows Vista or later.

: , , pre-Vista Windows RtlCompareUnicodeString, CompareStringOrdinal Windows NT.

+3

Source: https://habr.com/ru/post/1733165/


All Articles