It sorts by name, but there is a big problem with golang string comparison.
If you consider these two strings:
str1 : "hello.20190305-102.txt"
str2 : "hello.20190305-99.txt"
Then we should say that str1 > str2.
But go returns str1 < str2
On Wednesday, August 19, 2015 at 3:10:41 PM UTC+5:30, Arie
It's sorted lexically by the unicode code points. Why would str1 come
after str2? '1' < '9'.
On Fri, 2019-07-05 at 21:23 -0700, shubham.pendharkar via golang-nuts
wrote:
> It sorts by name, but there is a big problem with golang string
> comparison.
> If you consider these two strings:
> str1 : "h
Indeed, you have two choices: create file names with fixed width numbers:
Printf “file%08dv%02d.dat”, f,v
Or do a string/number parse of the names before sorting and separate the
numbers, you can insert spaces/zeroes and then string sort, or you can
parse the numbers and compare them numerically.