Why do files and directories with no time/date mess up sorting in Explorer?
If you have a file or directory that does not have a last-modified date, you may find that it causes Explorer to sort very strangely. (How do you get a file or directory with no last-modifiied date? It’s hard to do; you need the help of an external file system.) Why is this? As we learned earlier, a sort comparison function must impose a total order in order to produce consistent results. The problem is that Explorer’s comparison function mis-handles files and directories with no last-modified date. To get some more of the background behind this, you need to know about so-called “simple pidls”. A simple pidl is an item ID list that refers to a file or directory that does not actually exist. The problem is that a valid file or directory with no last-modified date looks just like one of these simple pidls becauses Explorer uses the last-modified date to distinguish whether it is manipulating a real pidl or a simple one. The problems with sorting occur when it comes time to decide where in the list these “real pidls that are mistaken for simple pidls” go into the sorted list. Explorer tries to keep all folders together, but if it sees a “simple pidl” it can’t tell whether that item is a folder or a file (after all, something that doesn’t exist is neither a file nor a folder) and it ends up producing inconsistent comparison results.
Moral of the story: Be careful with your sort functions. If you produce inconsistent results in your sort function, you will get inconsistent results in your “sorted” output.