Windows Explorer sort method

前端 未结 8 1227
萌比男神i
萌比男神i 2020-12-11 00:33

I\'m looking for an algorithm that sorts strings similar to the way files (and folders) are sorted in Windows Explorer. It seems that numeric values in strings are taken int

相关标签:
8条回答
  • 2020-12-11 01:24

    The way I understood it, Windows Explorer sorts as per your second example - it's always irritated me hugely that the ordering comes out 1, 10, 2. That's why most apps which write lots of files (like batch apps) always use fixed length filenames with leading 0's or whatever.

    Your solution should work, but you'd need to be careful where the numbers were in the filename, and probably only use your approach if they were at the very end.

    0 讨论(0)
  • 2020-12-11 01:26

    Explorer uses the API StrCmpLogicalW() for this kind of sorting (called 'natural sort order').

    You don't need to write your own comparison function, just use the one that already exists.

    A good explanation can be found here.

    0 讨论(0)
提交回复
热议问题