Varun Sharma Posted May 10, 2009 Report Share Posted May 10, 2009 Hi,I want to know what type of logic / algorithm windows uses to sort files ? For example:- following is the ordering of the text files by name ! If there is any article from microsoft regarding the algorithm / technique then that will also be good !01w0101w101w01az000z00z00pz0pHow come the file 01w01a comes after 01w1 ?Thanks Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted May 11, 2009 Report Share Posted May 11, 2009 Welcome to the Windows Forum.Very good question - I have sometimes wondered about that myself. I just had a look at my "My Pictures" folder, and the sort sequence is quite out of whack. I first thought it may have something to do with different file types, but even those that are all JPG, the sequence is not right.I will do some investigation and try to find an answer for us. Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted May 11, 2009 Report Share Posted May 11, 2009 Found something interesting: http://www.softwaretipsandtricks.com/windo...indows-ExplorerI have just added that key and value to the registry, but the sort order is still off. Maybe I need to restart Windows?Just rebooted, but nothing's changed. Quote Link to comment Share on other sites More sharing options...
Xavier Posted October 21, 2009 Report Share Posted October 21, 2009 I wanted to sort elements and I was asked to follow the windows way of sorting file in the explorer so I had a look at it.It seems to me that windows splits the name in groups of numbers or characters and then apply the sorting per group.so in your example, 1) 01w01 is split in 3 groups "01", "w" and another "01"2) 01w1 is split in 3 groups "01", "w" and "1"3) 01w01a is split in 4 groups "01", "w", another "01" and "a"then it compares group by group.The first 3 groups are all the same thing for it (01 == 1) and only one has a fourth group, so it comes after. 3) is last in this sortFor the first 2, as they are equal as per the first sorting loop, it applies an alphabetical order on digits on each group to distinguish them. alphabetically 01 is before 1, so 01w01 is before 01w1This way, z00p is before z0p because 00 is before 0, but they both are behind z000 and z00, as they contain a 3rd group that make them come after. (z000p would come after z00 too.Now if you look at the old way, it was just considering characters and not grouping. It is fine, when the files are named knowing that (in the case of the example of softwaretipsandtricks website mentionned, the windows file have been created knowing the old sorting. But this old sorting was puting 2 after 10, which might be confusing too (eg: a future Ie10 will come before Ie4_01 in the list...)So no sorting will suit you, unless you name your files for the specific sorting. Quote Link to comment Share on other sites More sharing options...
Xavier Posted October 21, 2009 Report Share Posted October 21, 2009 I forgot to mention, the best way to reproduce this sorting is to use regular expressions and extract alternatively groups of digits or letters from your elements, sorting the list per group. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.