dir() does not sort the returned information . It uses the order of entries returned by the operating system . In turn the operating system delegates to filesystem code. Different filesystemss have different sorting rules .
Some filesystems are defined as sorting directories as most recently used first out of the complete directory . Other filesystems divide the directory into blocks and rewrite one block at a time according to most recently used within the block . Others use binary tree representations .
MS Windows NTFS does not appear to formally define the sorting order . However in practice it appears to sort according to the utf16 non-canonical Unicode representation of the filenames . Apple's HFS+ is defined to sort according to utf16 representation of canonical Unicode .
Now one aspect of sorting according to complete filename including extension is that period sorts before the digits. That means that AA1.csv sorts before AA10.csv but it also means that AA10.csv sorts before AA2.csv . Files do not sort in the order 1 2 3 4 5 6 7 8 9 10 11 12 and so on: they sort in the order 1 10 11 12 ... 19 2 21 ... 29 3 30 31 ... 39.
That is probably what you are observing : they probably are in sorted order but the sorting is by characters not dictionary order . Likewise Spanish LL will not sort immediately after L as is defined for Spanish dictionary order .
You might want to look in the file exchange for natsort routines .
Best Answer