Jump to content

Windows File Sorting Algorithm


Recommended Posts

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 !

01w01

01w1

01w01a

z000

z00

z00p

z0p

How come the file 01w01a comes after 01w1 ?

Thanks

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 months later...

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 sort

For 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 01w1

This 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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy