[This post contains formatting and embedded images that don't appear in email. View the post in your Web browser.]
More than you could possibly want to know about this:
When sorting file names and folder names, LR uses an ordering similar to that of Mac Finder and Windows File Explorer. These orderings treat numbers within the names numerically (ignoring leading zeros). But LR's ordering has an obscure bug, breaking comparison ties randomly rather than using a consistent rule.
Gory Details
They first split a name into subsequences of non-digits and digits. E.g. "c02x" is split into three subsequences "c", "02", "x". Then when comparing two names, the subsequences are compared in turn. Subsequences of non-digits are compared lexicographically, while subsequences of digits are treated as whole numbers and compared numerically.
For example, consider the comparison of names "c2" and "c02x". They are first split into subsequences:
c, 2
c, 02, x
The first subsequences "c" and "c" are compared alphabetically, and they are equal. So the second subsequences "2" and "02" are compared, and since they are both numbers they are compared numerically, and they are equal. The first name has no more subsequences, while the second one has "x", so the first name comes before the second.
Finder, File Explorer, and LR differ in how they handle comparisons of numeric subsequences with leading 0s. It appears that when Finder has two names whose subsequences are equal, it breaks ties by putting the shorter name first (e.g. "c1" before "c01"). Whereas File Explorer breaks ties by comparing the entire names lexicographically (e.g. "c01" before "c1").
But it appears that LR doesn't have a rule for breaking ties and uses whatever order its sort algorithm produces. It looks like the sort algorithm is technically "unstable", meaning that there's no consistency in how ties are handled. That explains why your first screenshot shows "C01" followed by "C1", while the second screenshot shows "C1" followed by "C01".
I think it's a bug that LR's sorting is unstable and breaks ties randomly. But I also know that Adobe will pay zero attention if you file a bug report 😆
An interesting aside: File Explorer sorts file names using the algorithm I described above, but it sorts folder names strictly lexicographically.
Here's a screenshot showing how Finder and File Explorer sort file names, and how LR, Finder, and File Explorer sort folder names:
