Sort numeric files in Windows



  • I have a list of files like:

    007_601_1
    007_601_2
    007_601_3
    007_601_10
    007_601_11
    007_601_12
    

    When I sort it using QDir::Name I get the following order:

    007_601_1
    007_601_10
    007_601_11
    007_601_12
    007_601_2
    007_601_3
    

    However, I need the order as mentioned in the first file list. Is there a way to sort like this or do I need to write my own piece of code which does it?



  • AFAIK functions like QDir::entryList sort file names only in alphabetical orders.

    If you want to achieve different results you will need to write your own sorting code.



  • Is QCollator::compare a good option for this? I mean, I simply implement a sorting algorithm based on the result from QCollator::compare. Usually the number of files will be limited to ~3000.